RTC Calculated value script problem with update and read-only field
Hello,
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
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
Hi Marko,
I have a solution for you.
1. Create calculated script which will collect the tags, and give the number of them. In RTC development background, tags are fetched like this: |these|are|four|tags| even they are displayed in wi as: these, are, four, tags.
So, you need to get them from the attribute tags, then in JavaScript split them by ("|").
You will get the number of tags two more (because of "|" at the start and at the end of tags). Then, you need to substract value 2 from array given by the split function.
2. Create new custom attribute NumberOfTags to be integer, set calculated value from first step, and add Dependency to be attribute Tags.
3. Add custom attribute NumberOfTags on editor presentations level of specific wi type, and set it readonly on this level if you want.
4. List by work item query all your work items which were tagged before, synchronize them to get new attribute NumberOfTags, and at this moment, duirng synchronization, you 'll see that your new attribute NumberOfTags is being populated with number of tags.
I tried it a few moments ago, and it works.
Let me know if you need the script.
6 other answers
The only thing I can think of for 1 is to export the WI's with the tags, make the calculation in excel, and then re-import the calculated value for those WI's that had tags. The whole scripting environment is a bit of a mystery, there may be a better way?
As for 2, make the attribute read only in the editor presentation only, not at the attribute level.
Comments
For 2: you don't make the attribute read-only, but the presentation of the attribute. I will have to check, because I was under the impression the scripts could write into read only attributes. However I checked if the API can write read only attributes and it can't in 5.x. So I am a bit confused how you would be able to get anything into a read only attribute, if neither scripts nor the API can actually do anything with it.
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.
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.
An update...... I tried again.
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.
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
showing 5 of 6
show 1 more comments
Hi Marko,
you can calculate number of tags in integer field, but if you want integer field readonly, you must set it up on editor presentations level, not directly on attribute.
I've already done this, but I must find example and I can send it to you if you want.
The best way to get calculations when you deploy your script file is to synchronize attributes and you will get the values on all sychronized work items.
Comments
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