It's all about the answers!

Ask a question

Calculated Value that also allows for manual setting of field?

Vince Thyng (13724153) | asked May 07 '14, 1:13 p.m.
I have a Calculated Value script working when Status (state) changes to set a custom date field (Verified Date).  We also want to be able to manually set this value to correctly set dates before this script existed.  When I save the manually selected date in eclipse, the date returns to blank.  I saw a comment in the wiki about making Calculated Values read only in the presentation, but are you actually prevented from making manual updates to fields with a script associated with them?

Vince Thyng commented May 07 '14, 1:40 p.m. | edited May 07 '14, 1:43 p.m.

<removed comment, it was unrelated>

Accepted answer

permanent link
Ralph Schoon (63.3k33646) | answered May 08 '14, 5:03 a.m.

as far as I can tell, you are not required to make the attribute read only. However, every time the calculation script affecting this attribute you have to decide if you want to overwrite it. This is often not easy to do. As described in you can return the current value or a calculated value. You would have to make a decision somehow.

Please let us know if it works for you.
Vince Thyng selected this answer as the correct answer

Vince Thyng commented May 08 '14, 9:56 a.m.

Thanks Ralph.  I have my Calculated value setup to only run when there is a Staus (state) change, so I was surprised to see my manual change of the my custom date get reset immediately to blank when I saved.  I am not expecting my script to be running at that point.

The bigger issue I have run in to is that I can't access my custom field from the Calculated Value js script, so I can't return the current value when the script runs.  So as you mentioned, it will get blanked out anyway if the state change I am interested in doesn't meet my script's logic criteria.

One other answer

permanent link
Henrik Westrell (1024) | answered May 10 '14, 4:54 a.m.
It is easy to get a custom attribute's current value:
currentValue= workItem.getValue('attribute id');
contactName = workItem.getValue('defect.mycustomAttribute');

But, as Ralph mentioned you have to return some value, or else the attribute's current value is erased.
I will play with exceptions to see if that works instead. Since I'm having problems with the shared HTML attr. "Summary" I would like something like this:

If type = defect then
 return some-text

Vince Thyng commented May 12 '14, 3:30 p.m.

Thank you Henrik, this actually solves the problem have!  For some reason I was thinking I needed to use the fields available with workItem.getValue(WorkItemAttributes.*).  In my case 'defect.testdate' did not see it, but just 'testdate' did.

If you do test exception handling too, I would be curious of the results.

Henrik Westrell commented May 12 '14, 4:47 p.m.
To code below seems to work. Throwing an exception (to avoid taking care of get/set the Summary current value) might have side-effects, but it works so far for me in eclipse and chrome...

if ( Type == "defect" ) {

return "something";
} else {
throw 0;

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.