It's all about the answers!

Ask a question

How to get a calculated value script to store a timestamp into an attribute ?


long TRUONG (3654123147) | asked Mar 25 '14, 9:55 p.m.
 First time using script based provider. Spent almost a day on it, still couldn't get it to work yet?

We have a small string attribute for date&time in text (validated with a regular expression) with a timestamp attribute as its dependency.

Eventually we will want to convert the text time into a timestamp to store in the TS attribute. But for now, as we kept failing to get it to work, we are just trying to: 
  • store current date&time, with new Date(), into the TS attribute (which had been tried with ReadOnly too)
  • when the txt attribute is modified and the WI get saved.
  • With the below Calculated Value script:
dojo.provide("com.acn.dor.scripts.validators.StoreTextTimeAsTimestamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); 
dojo.require("dojo.date"); 
dojo.require("dojo.date.stamp"); 

(function() { 

var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; 

var StoreTextTimeAsTimestamp = dojo.declare("com.acn.dor.scripts.StoreTextTimeAsTimestamp", null, { 

    getValue: function(attributeId, workItem, configuration) { 

    // var dateTimeString = workItem.getValue(WorkItemAttributes.com.acn.adt2.workitem.attribute.custom1_defect);    
var dateTime = dojo.date.stamp.fromISOString(new Date(), {milliseconds:true, zulu:true});
        return dateTime;  
    } 
}); 
})(); 

One answer



permanent link
Ralph Schoon (63.7k33648) | answered Mar 26 '14, 8:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I don't see a description what happens or what does not. Supposing your script is syntactically correct, the one thing you would have to do, is to set the dependency to the attribute that, when changed, would trigger the script and thus setting the calculated attribute (referred to as txt). You can only react on change of the attribute. When the attribute is changed, the calculated value is triggered. Just saving the work item would not trigger the calculated value.

You might want to look into https://jazz.net/library/article/1093 Lab 5 for some more hints on JavaScript.

Comments
long TRUONG commented Mar 26 '14, 8:45 a.m.

What we'd like to achieve is: 

  • When any change on the txtAttrib (with a reg exp validator) is made 
  • It will trigger the Calculated Value script  tied with the TSattrib.
  • This script will return hence store a timestamp into the TSattrib
Do we make txtAttrib a dependency of TSattrib ? or vice versa ? We had tried both ways actually, neither works.

Nothing get stored in TSattrib.


Ralph Schoon commented Mar 26 '14, 9:26 a.m. | edited Mar 26 '14, 9:26 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

To trigger the calculated value for TSattrib, you need to add a dependency to txtAttrib to TSattrib. This will trigger the calculated value script when txtAttrib changes.

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.