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
Hi Ralph,
I am aware of that link on interpreting the timestamp type attributes.
I have tried to get the UID of value "None" using conversion as well for using in the above script. It does not return any UID value for "None".
eg:
return dojo.date.stamp.fromISOString(workItem.getValue(WorkItemAttributes.DUE_DATE));
In the else part of the script I pasted, it is just returning the current value, if state is not 3.(Not to change any thing).
If you feel some thing is wrong in the script, Please post the correction.
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.Let me summarize what I think you are trying to do -- please correct me as needed.
Udaya Puthuraya
Feb 04 '13, 10:15 p.m.Millard,
Your statements are mostly right except for "custom.attribute.TimeStamp" is not set to read-only. I can fill in any valid date value for that.
As you correctly mentioned, When the work item state is changed to 3 , it's value need to be cleared. In all other state changes/states just return the current value.
Configuration block:
<valueProvider
... Auto populated lines after adding the script ...
<ClearCA unassigned_value="None"/>
</valueProvider>
I also tried following for the ClearCA element.
<ClearCA unassigned_value=""/>
<ClearCA unassigned_value="Unassigned"/>
Thanks, Udaya
Millard Ellingsworth
FORUM ADMINISTRATOR / JAZZ DEVELOPER Feb 05 '13, 12:42 p.m.What Ralph said, too. Also, while it is not a requirement, it is recommended that attributes with calculated value providers (different than default value) should be read-only. Your case is a little different, since all you really want to do is clear the value when it is saved with a certain state. Let us know if this information does not give you enough to get things working.
Udaya Puthuraya
Feb 05 '13, 1:38 p.m.No. It is still not working, as I posted reply to Ralph's comment.
I was aware of the link posted by Ralph and have played around with that, before opening this question in the forum.