It's all about the answers!

Ask a question

RTC - Date Difference Script


V Niranjan (12545374) | asked Jul 11 '15, 10:20 p.m.

Hi

The following script is not working. Request your help.

 I have created a custom attribute of Integer type and added Due Date as dependency but the result is shown as  0.

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

 (function() {
dojo.declare("org.scripts.datediff", null, {

     getValue: function(attributeId, workItem, configuration) {

            var dueDate = dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
         var currDate = new Date();
                
         var day = dojo.date.difference(currDate, dueDate, "day");
        
         return day;
     }
 });
 })();

Regards

Niranjan V

Accepted answer


permanent link
Ralph Schoon (63.3k33646) | answered Jul 13 '15, 5:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 13 '15, 5:07 a.m.
The script has to return the date like this:

/*******************************************************************************
 * 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 to compare two dates
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});
		return date;	
		
        }
    });
})();
As explained in https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript (carefully read it) the date has to be returned as ISOString so you have to convert it back like this:

var date= dojo.date.stamp.toISOString(now, {milliseconds:true, zulu:true});
V Niranjan selected this answer as the correct answer

One other answer



permanent link
Ralph Schoon (63.3k33646) | answered Jul 12 '15, 6:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
It is not working, because you don't convert the date back to something RTC can understand.You use fromISOString to get the date format and you have to use toISOString for the format to be converted to return it. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript

Comments
V Niranjan commented Jul 13 '15, 4:41 a.m.

Hi Ralph

If possible please let me know the changes to be done to the script. Not sure if I got it correct.

Regards
Niranjan V

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.