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 |
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.
Marko Tomljenovic selected this answer as the correct answer
Comments
Marko Tomljenovic
commented Sep 03 '14, 10:09 a.m.
Thank you for your solution proposal.
Milan Krivic
commented Sep 03 '14, 10:34 a.m.
If you are satisfied with this question, please mark it as Accepted.
Thanks
Marko Tomljenovic
commented Sep 03 '14, 10:55 a.m.
I will after Ralph gives feedback on my (presumably) last comment above :)
|
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
Marko Tomljenovic
commented Sep 03 '14, 3:28 a.m.
Am I lucky that I first started with the excel based solution and then switched to the scripts :)
|
Ralph Schoon (63.5k●3●36●46)
| answered Sep 03 '14, 3:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. |
Ralph Schoon (63.5k●3●36●46)
| answered Sep 03 '14, 4:44 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. Comments
Marko Tomljenovic
commented Sep 03 '14, 10:09 a.m.
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.
Ralph Schoon
commented Sep 03 '14, 11:42 a.m.
| edited Sep 03 '14, 11:45 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
Marko Tomljenovic
commented Sep 03 '14, 11:50 a.m.
Ok fine.
Ralph Schoon
commented Sep 03 '14, 11:57 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
Milan Krivic
commented Sep 04 '14, 3:52 a.m.
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.
I 've created another custom attribute integer and made it hidden, and on query results, I 've been changing it to different values, just to produce any work item changes.
Like Ralph said, make sure to query all necessary work items.
Marko Tomljenovic
commented Sep 04 '14, 4:16 a.m.
It is a bug since it does not work.
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 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.
Milan Krivic
commented Sep 03 '14, 5:54 a.m.
Ralph,
I tried with attribute integer, and made it readonly at attribute level, and calculation didn't work. When I changed it not readonly at attribute level and made it readonly on editor presentations level, it worked.
So, I also assume that it is a defect.
|
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 |
subscribing then unsubscribing on mass seems to work for us, may be a better answer than the others provided here ;-)
|
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.