Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

RTC - Date Difference Script

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

0 votes


Accepted answer

Permanent link
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

0 votes


One other answer

Permanent link
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

0 votes

Comments

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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,030

Question asked: Jul 11 '15, 10:20 p.m.

Question was seen: 3,150 times

Last updated: Jul 13 '15, 5:07 a.m.

Confirmation Cancel Confirm