RTC Calculated value script problem with update and read-only field
I have used a calculated value script to fill in an integer custom attribute depending on the number of certain words in the tags of the work item. Now I have two problems:
1. I have added the script after a lot work items have been already created and tagged. How can I trigger the recalculation of the attribute? Using the one hint from the forum with bulk editing the tags via the Eclipse client does not work(https://jazz.net/forum/questions/111839/how-to-recalculate-script-based-calculated-values-for-all-wi-after-changing-the-script). The value only is updated when I change the tags in the WI editor (Eclipse and Web works) directly and save the work item. I cannot go manually over all single work items for the recalculation to happen. Is there a better way?
2. I want this calculated attribute to be read only. But when I enable the checkbox "readonly" in the custom attribute definition dialog. I cannot save anymore the work item in case the calculated value changes due to the script. How can I make this attribute read only so that only the script can do changes?
PS. We are using RTC 4.0.6 at the moment.
Thank you for your help
Accepted answer
6 other answers
Comments
Am I lucky that I first started with the excel based solution and then switched to the scripts :)
So I did reuse the excel to set the initial values.
Could you ask somebody that knows about the scripting environment? Otherwise I wil file a bug on that!
Just a question out of curiosity: If I set an attribute to be read only on attribute level how can then a value be set at all for those attributes? What is the meaning of this switch.
For 1: I would suggest to try to change an attribute that is set as a dependency for the calculated attribute. If a dependent attribute is changed, this should trigger the script execution. This should work in the Eclipse as well as the Web UI. You could check the logs if something actually happened. See https://jazz.net/library/article/1093 lab 5 or https://jazz.net/wiki/bin/view/Main/AttributeCustomization for where to find the logs.
I was able to make the attribute read only (not the presentation) and it was set with the correct value using a script. I tried that in 4.0.3 and 5.0, so it should work for you too.
In 5.0 I was not able to set the the read only attribute with a Plain Java Client Libraries tool using the API - I need to investigate if that was possible in 4.x.
I also tried (with 4.0.3) to synchronize attributes. In the work Item customization editor click "check attributes usages in repository". If the Eclipse client prompts to synchronize attributes, select that. The new attribute is added to all the work items that don't have it and the calculation is executed.
Comments
The problem with synchronize is that I can only synchronize if new attributes are added but not if I only change the setting for calculated values provider or I even only change the javascript implementation.
Then I can't even synchronize since the work items already have the new attribute and have already been synchronized before.
There is sth necessary like a forced synchronize that always runs.
The only idea I would have is some hidden attribute, that you use as trigger dependency. The script based calculated values are not designed to detect that the script changed as far as I can tell.
Such a trigger attribute the value provider depends on too, where you simply enter a different value, would be able to trigger the script. You could use https://rsjazz.wordpress.com/2012/11/19/using-an-expression-to-synchronize-attributes-for-work-items-of-a-specific-type/ in conjunction with https://rsjazz.wordpress.com/2013/01/02/working-with-work-item-attributes/ to set the attribute (e.g. the script change date) in a batch mode.
You basically would otherwise have to induce a change that triggers the calculated attribute, so you either change all tags - add a fake one, save all, remove it, save all. Or you can use a mechanism as discussed above.
Keep in mind that queries have a result limit.you would only be able to affect as many as are within your limit in the UI. The API can circumvent that. You could also try to force a save using the API. I am not sure if a save would happen without an attribute change, however.
Ok fine.
Then I will file two defects:
1. Read-Only switch does not work for Integer based attributes together with Calculated value script
2. Bulk-Editing tags via Eclipse client query does not trigger calculated value script depending on tags.
Bulk editing the tags should trigger that script - if it has a dependency set to the tag attribute. If it doesn't and you have set the dependency, that would be a defect. So did you and does it? You have to add a fake tag to all however. If the value is not changing, it might not save - per design.
The query limit is as designed you can either set the limit higher (and risk that users load the system with huge queries) or you can use the APi as suggested.
I had a situation a few months ago when I 've already synchronized work items with new custom attribute, then I needed to calculate something in new custom attribute.
It is a bug since it does not work.
I have filed a defect: https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=329988
Comments
Milan, I made an attribute (string) read only and the attribute customization was able to write it. I doubt it is different for different attribute types - if it is that should be a defect.
Ralph,
I am trying to do a similar thing so that I can auto increment my Change Request #s and my Defect #s Unfortunately I do not know how to script this.
Do you have any suggestions my conventions are as follows.
Defects - "YYYY-nnn" - where YYY is the current year
Change Requests - "PROJ-CR-nnn" where PROJ is the project name