It's all about the answers!

Ask a question

How to set the value of custom attribute of type timestamp to Null(None) using javascript. ?


Udaya Puthuraya (8811421) | asked Feb 04 '13, 2:57 p.m.
edited Mar 21 '13, 12:18 p.m. by Ralph Schoon (63.4k33646)

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");
         }
 
    }
});
})();
================================================================

Comments
Millard Ellingsworth commented Feb 04 '13, 4:51 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

Let me summarize what I think you are trying to do -- please correct me as needed.


You have a custom attribute that is a timestamp type (I'm guessing it's ID is "custom.attribute.TimeStamp"). This script is set as a value provider attribute customization on that attribute (which means the attribute is read-only and always gets its value from this script). I'm presuming this attribute is set to be dependent on State?

When the State is "3", you want to clear the value, retrieving a value from the configuration that you stored there (presumably the "None" UUID). When the state is anything else, you simply want to return whatever value the field currently has (so that it does not change).

Can you show the configuration block you added for retrieving the value?

Thanks...Millard



Udaya Puthuraya commented 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 commented Feb 05 '13, 12:42 p.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER

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 commented 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.

Accepted answer


permanent link
Udaya Puthuraya (8811421) | answered Mar 14 '13, 12:36 p.m.
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

Comments
Ralph Schoon commented Mar 14 '13, 1:30 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Thanks for sharing!

2 other answers



permanent link
Anil Patel (1) | answered May 04 '14, 8:26 p.m.

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


permanent link
Ralph Schoon (63.4k33646) | 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
Udaya Puthuraya commented Feb 05 '13, 11:34 a.m.

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.


Your answer


Register or to post 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.