It's all about the answers!

Ask a question

Set the Due Date automatically based on creation date


Anand K (825) | asked Apr 11 '18, 4:01 a.m.
retagged Apr 25 '18, 11:19 a.m. by Ken Tessier (84117)

I need to set the Due Date attribute automatically as X days ahead of creation date for Defect WI.

for e.g. Due Date = Creation Date + 7 days

I wrote a dojo script for that in Attribute Customization -> Calculated Values. And then edited the Due Date attribute for Defect WI to get the Calculated Value from the script.

But may be somewhere my script is wrong or something else, so it's not working.

Please check the script I wrote:

dojo.provide("com.example.DueDateProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {

dojo.declare("com.example.DueDateProvider", null, {

        getValue: function(attribute, workItem, configuration) {
       
        if(workItem.getValue(WorkItemAttributes.TYPE) == "defect" ){

// How to set the value of Due Date atrribute? I guess below line is not correct.
     WorkItemAttributes.DUE_DATE = workItem.getValue(WorkItemAttributes.CREATION_DATE) ;

    
        }

return workItem.getValue(WorkItemAttributes.DUE_DATE);


        }
    });
})();

Accepted answer


permanent link
Ralph Schoon (63.1k33645) | answered Apr 17 '18, 6:56 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Apr 17 '18, 6:58 a.m.

Check https://jazz.net/library/article/1093 and check the last lab. Do some debug outputs to the console and read them.
check https://jazz.net/library/article/1360 and try debugging. Use Crome for that.

At the moment I would not even know if you enabled scripting or anything works as you do not provide any useful information. The code below worked for me - does not help if we don't even know if you are able to use it.

You did not seem to have read https://jazz.net/wiki/bin/view/Main/AttributeCustomization the section about conversion of dates very good, either. See the conversion direction below and compare it to yours.

/***********
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2011. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. ***********
/ dojo.provide("com.team.example.CurrentDate");

dojo.require("dojo.date"); // We need the date class from Dojo dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings

(function() { dojo.declare("com.team.example.CurrentDate", null, {

    getDefaultValue: function(attribute, workItem, configuration) {

    var now=new Date();
    var date= dojo.date.stamp.toISOString(now, {milliseconds:true, zulu:true});
    console.log("Now is: " + date);
    return date;

    }
});

})();

Anand K selected this answer as the correct answer

Comments
Anand K commented Apr 18 '18, 1:19 a.m.

I got to know the problem was in work item type condition,
  if(workItem.getValue(WorkItemAttributes.TYPE) == "defect" )

When I commented above line, simple return statement was reflecting in due date field:
return workItem.getValue(WorkItemAttributes.CREATION_DATE);

Is there any issue in conditional statement?


Anand K commented Apr 18 '18, 1:22 a.m.

Now I updated the script to add 7 days without WI type condition. It works but while I create the WI, it shows default value in due date field as "Jan 8, 1970, 5:30:00 AM" which gets updated once I save the WI. Is there a way to show nothing when we just click to create WI?

(function() {
     var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
     dojo.declare("com.example.DueDateProvider", null, {
        getValue: function(attribute, workItem, configuration) {
        var creationDate = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
        var dueDate = dojo.date.add(creationDate, "day", 7);
        var date= dojo.date.stamp.toISOString(dueDate, {milliseconds:true, zulu:true});
        return date;
       }   
    });
})();


Anand K commented Apr 18 '18, 2:14 a.m.

In addition to default due date value, there is another issue that we can't change the due date to any other date. When I change it, while saving it reverts back to the calculated date (creation date + 7 days)


Ralph Schoon commented Apr 18 '18, 2:14 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
  1. The creation date is NOW
  2. You can hide an attribute presentation on creation

Anand K commented Apr 18 '18, 2:14 a.m.

In addition to default due date value, there is another issue that we can't change the due date to any other date. When I change it, while saving it reverts back to the calculated date (creation date + 7 days).

The conditional statement is fixed.


Anand K commented Apr 19 '18, 4:51 a.m.

@Ralph

Sorry, I didn't get this:

  1. The creation date is NOW
  2. You can hide an attribute presentation on creation

May be I should ask a separate question for the issues.


showing 5 of 6 show 1 more comments

2 other answers



permanent link
Ralph Schoon (63.1k33645) | answered Apr 11 '18, 6:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

JavaScript provides ways like dojo.date to work with dates. 

You can not simply add some stuff and hope to get something useful what would Apple+5 be?

The following code shows some ways how working with dates can be done. Note that you have to convert back and forth as described in https://jazz.net/wiki/bin/view/Main/AttributeCustomization

       // Work Item new: not initialized - provides todays date. Once created provides the creation date 
        var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("com.ibm.team.workitem.attribute.creationdate")); 
        // Get the current attribute's value and make a Date object from it
        console.log("I got: ["+workItem.getValue(attributeId)+"]");
        var endDate= dojo.date.stamp.fromISOString(workItem.getValue(attributeId));      
// Compare the two dates returns negative value due to order var compare = -(dojo.date.difference(endDate, beginDate, "day")); if (compare>= 30) { // make sure endDate is not earlier than beginDate + 30


Comments
Anand K commented Apr 11 '18, 11:41 p.m.

Thanks for your hint, I'll try it out.


permanent link
Donald Nong (14.5k414) | answered Apr 11 '18, 10:41 p.m.

I'm surprised to see so many mistakes in such simple script. Put it bluntly, of those lines that you need to modify and have modified from the example skeleton, none is correct (not just the calculation of date). I strongly suggest you read the API specification first before trying to write any codes.
https://jazz.net/wiki/bin/view/Main/AttributeCustomization

Note that the script does not appear to be triggered by the Creation Date attribute at all. It may be due to the way (timing) the system sets its value. You may need to use other mandatory attribute such as Summary to trigger the script.


Comments
Anand K commented Apr 11 '18, 11:39 p.m.

Yes, you're right. I modified it from the example skeleton. I'm new bee to this, didn't have any idea where to refer to API's for it. Thank you for your suggestion.


Anand K commented Apr 12 '18, 4:52 a.m.

I updated the script, but not getting how to set the Due Date attribute to some value. As of now I'm trying to set it to Creation Date value, later I'll modify to add 7 days.


Ralph Schoon commented Apr 12 '18, 6:01 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You can not set an attribute value in an attribute customization script. You can create a calculated value and return the value.

Perform https://jazz.net/library/article/1093 the RTC Only version or at least work through the last lab.

Also read the help topic and the related links:

https://jazz.net/help-dev/clm/topic/com.ibm.team.workitem.doc/topics/c_calc_val_attribute_config.html


Anand K commented Apr 17 '18, 6:04 a.m.

I changed the script to first set the Due Date attribute as of creation date only just to see if it reflects, but it's not happening. Please check the code;

dojo.provide("com.example.DueDateProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");

(function() {
     dojo.declare("com.example.DueDateProvider", null, {
        getValue: function(attribute, workItem, configuration) {
     
            if(workItem.getValue(WorkItemAttributes.TYPE) == "defect" ){
             return dojo.date.stamp.fromISOString(workItem.getValue(com.ibm.team.workitem.attribute.creationdate));
         }
       }   
    });
})();


Anand K commented Apr 17 '18, 6:08 a.m.

I tried to return in this way also, but not working.

            // return dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
            // return workItem.getValue(WorkItemAttributes.CREATION_DATE);

I tried setting the dependencies to many attributes but nothing worked.

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.