How to set the value of custom attribute of type timestamp to Null(None) using javascript. ?
![]()
Udaya Puthuraya (88●1●14●21)
| asked Feb 04 '13, 2:57 p.m.
edited Mar 21 '13, 12:18 p.m. by Ralph Schoon (63.3k●3●36●46) 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
![]()
I defined variable as below and used it as return value based on the condition.
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; } Ralph Schoon selected this answer as the correct answer
|
2 other answers
![]()
Ralph Schoon (63.3k●3●36●46)
| answered Feb 05 '13, 3:17 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Please be aware that you need to use the API correctly to be able to interpret the timestamp type attributes.
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,
|
![]() 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");
please help
|
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.
Comments
Let me summarize what I think you are trying to do -- please correct me as needed.
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
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.
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.