It's all about the answers!

Ask a question

Javascript updates the date everytime there in an update on the workitem


Pavithra Kasturirangan (42955956) | asked Aug 17 '12, 2:58 a.m.
 Hi,

I have a javascript which has to update a field called "Indate" whenever the state moves from New to In Progress or from Testing to Inprogress. 
The field should be updated whenever it has the state moved to In progress.

This is my javascript:-

if (currentWorkitem == 'defect' && currentState == requiredState)
var today = new Date();
var newDate = today.getTime() + "";
return newDate;
}
else {
return null; 
}

I have made Status as a dependent item on the Indate attribute.

The problem that i find is that whenever something is changed on the workitem that is in "In progress" state, the date is updated. The date has to update only when the change is the status change to "In progress" and not on any update that happens on the workitem that is in "In progress" state.
When i check the console logs, the logs are not updated on any change to the workitem, the log is created only when there is a status change, but in the foreground it updates the date everytime.

Can someone tell me why this happens ? 

Accepted answer


permanent link
Ralph Schoon (63.1k33646) | answered Aug 17 '12, 3:13 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
As far as I am aware it is impossible to detect a state change in Javascript. At least I was not able to do it. All you get is the current state. I have no solution for that other than creating a plugin e.g. an OperationAdvisor or OperationParticipant (See Extensions workshop in the libary https://jazz.net/library/article/1000 ).
Pavithra Kasturirangan selected this answer as the correct answer

One other answer



permanent link
Jared Russell (1.3k12019) | answered Aug 17 '12, 5:57 a.m.
edited Aug 17 '12, 5:58 a.m.
 Does the "Indate" field get populated before you move to the "In Progress" state?

If it is blank before your script populates it, you could have your script check to see if the value is null before setting the value to the current time:

var currentValue = workItem.getValue(attributeId);
//If current value is null then this is the first time the script has run
if(currentValue == null) {
  //Set time
}

Comments
Ralph Schoon commented Aug 17 '12, 6:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Good Idea. It will only work once though.

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.