Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes

Comments

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


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.


Accepted answer

Permanent link
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

1 vote

Comments

Thanks for sharing!


2 other answers

Permanent link
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});










0 votes

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.


Permanent link

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

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,937

Question asked: Feb 04 '13, 2:57 p.m.

Question was seen: 10,141 times

Last updated: May 04 '14, 8:26 p.m.

Related questions
Confirmation Cancel Confirm