How to set the value of custom attribute of type timestamp to Null(None) using javascript. ?
When trying to get the UID of custom attribute of type timestamp with value"None", it returns blank.
If I try to use the the blank value in the java script as below, value of custom attribute is not getting changed to "None".(Remains unchanged when the state changes)
Any thoughts on what is wrong with the script ? and
What is the correct UID for value "None", for an attribute of type timestamp ?
=============================================================
dojo.provide("org.example.ClearCustomTimestamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.ClearCustomTimestamp", null, {
getValue: function(attributeId, workItem, configuration) {
if (workItem.getValue(WorkItemAttributes.STATE) === "3") {
return configuration.getChild("ClearCA").getStringDefault("unassigned_value", "");
}
else {
return workItem.getValue("custom.attribute.TimeStamp");
}
}
});
})();
================================================================
Accepted answer
That seems to have helped, to set it to null in the custom attribute, through java script.
var NullDate = null;
if (workItem.getValue(WorkItemAttributes.STATE) === "3" && workItem.getValue("my.custom.attribute") === "cust.literal.l6") {
return NullDate;
}
2 other answers
See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript and look for Timestamp.
Timestamp as an ISO-8601 standard string. Use dojo.date.stamp to convert a Javascript Date object to and from an ISO-8601 string. When converting a Date object to a string set the milliseconds and the zulu options to true. To convert the value of a timestamp attribute with the id attributeId to a Date object use: var date= dojo.date.stamp.fromISOString(workItem.getValue(attributeId)); To convert a Date object to an ISO-8601 string use: var string= dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true});
Comments
solution provided by Udaya Puthuraya does not work for me. I have very simple logic as well
if status = Closed I want to set calculated field "Closeddate" to today's date if
status = re-open than Null
I tried example provided by Udaya Puthuraya but it did not work
I found old logic where it mentioned to use "0" but this sets default date of Dev 31'st 1969
here is my script
dojo.provide("com.impact.CalcClosedDate");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
dojo.declare("com.impact.CalcClosedDate", null, {
getValue: function(attribute, workItem, configuration) {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var Status= workItem.getValue(WorkItemAttributes.STATE);
var currentDate= new Date();
var NullDate= null;
if ( (Status=="com.ibm.team.workitem.defectWorkflow.state.s13") || /* Closed */
(Status=="4") ){ /*verified */
return currentDate.getTime().toString();
}
return NullDate;
}
});
})();
please help
Comments
Millard Ellingsworth
FORUM ADMINISTRATOR / JAZZ DEVELOPER Feb 04 '13, 4:51 p.m.Udaya Puthuraya
Feb 04 '13, 10:15 p.m.Millard Ellingsworth
FORUM ADMINISTRATOR / JAZZ DEVELOPER Feb 05 '13, 12:42 p.m.Udaya Puthuraya
Feb 05 '13, 1:38 p.m.