Return timestamp into custom attribute
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("cr.DateInitiated.genInfo", null, {
getValue: function(attribute, workItem, configuration) {
var currentDate = new Date();
var currentDateString= dojo.date.stamp.toISOString(currentDate, {milliseconds:true, zulu:true});
var date = dojo.date.stamp.fromISOString(currentDateString);
return date;
}
});
})();
One 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 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; } }); })();
Comments
That is a working default value for a date or timestamp attribute, as far as I remember. Maybe you are asking the wrong question?
I am asking how to return timestamp value into custom attribute (type of timestamp) when using javascript Date(). perhaps its javascript date format ... need to know how to return a date not string.
I already answered. As far as I can tell, this code should return the date for a timestamp attribute, regardless if custom or not. The code below returns the data in calculated and default values.
dojo.provide("com.example.ValueProvider");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.example.ValueProvider", null, {
getValue: 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; } });
})();
This reads the attribute value and makes it available as date in the script:
var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("com.ibm.team.workitem.attribute.creationdate"));
You can continue to ignore my answer. Or you try my code out and see that you have to return a string in the right format. I do not care any more. I will unsubscribe from this question.
var currentDateString= dojo.date.stamp.toISOString(currentDate, {milliseconds:true, zulu:true});
var date = dojo.date.stamp.fromISOString(currentDateString);
return date;
I actually ran the example, again before sharing, and it works for me.