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
Accepted answer
/******************************************************************************* * 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});