Calculated value based on enumeration literals
Hello,
We are using a 7.0 CLM environment. We have 3 attributes we'd like to be included in a calculated value - story points (complexity enumeration included in agile template), business value (complexity enumeration same as story points), and ROI (decimal data type). We would like to have a calculated value that takes the numeric value within the enumeration literals of Story points and Business Value to divide one by the other and populate the ROI decimal attribute with the resulting value. I am aware of the example calculated values that are provided in documentation but couldn't find how I could verify that the fetch of the attribute value represents a numeric value. This would take place on the User Story work item type (com.ibm.team.apt.workItemType.story) predefined in the scrum template and the ID's for business value and ROI are "businessValue" and "returnOnInvestment" respectively. Could anyone provide an example of the javascript that could make this work?
|
3 answers
Calculated values use Javascript, so you would use the parseInt() function to convert the values into integers, or the parseFloat() function to convert to floating point numbers.
Make sure you set the dependencies on the ROI attribute to be both the input values
/*******************************************************************************
* *******************************************************************************/ dojo.provide("example.roi.ValueProvider"); (function() { dojo.declare("example.roi.ValueProvider", null, { getValue: function(attribute, workItem, configuration) {
var businessValue = parseFloat(workItem.getValue("businessValue"));
var points = parseFloat(workItem.getValue("com.ibm.team.apt.attribute.complexity");
return (businessValue/points).toString();
} }); })();
Once you've created this customisation, you select it as the calculated value for the ROI attribute on the attribute itself, and select the Story Points and businessValue attribute as dependencies
Comments
Timothy Distel
commented Jan 04 '21, 12:57 p.m.
Hello Davyd,
Thank you for your response, this is very helpful. I used this code you provided and made sure to configure the calculated value for ROI as well as set the other two as dependencies, however the ROI attribute still remains blank when creating a new story with values for both story points and business value. Is there any other configuration that I might be missing?
Did you configure the dependencies? See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values for when scripts trigger.
Also: use Chrome to debug the script.
Ralph,
I did make sure to configure the other two attributes as dependencies on the configuration of the resulting attribute. Also, when I went to debug I didn't see the javascript of the calculated value at all in the sources. This lead me to believe the code may be fine but that there may be another configuration for the environment that I'm missing.
Also, I just checked to make sure that Enable Process Attachment scripts property is set to true, so its not that. Is there any obvious reason for this that you can see?
Davyd Norris
commented Jan 11 '21, 12:39 a.m.
Hi Timothy,
What if you slip in a couple of console.log() lines and see what is going on?
getValue: function(attribute, workItem, configuration) {
console.log("I'm here!");
var businessValue = parseFloat(workItem.getValue("businessValue"));
var points = parseFloat(workItem.getValue("com.ibm.team.apt.attribute.complexity");
console.log("bv = ", businessValue, ", pts = ", points);
console.log("ret = ", (businessValue/points).toString());
}
See if that gives you anything. When this runs on the server the console will print in the server log, and when it runs in the client it'll print in the browser console.
|
Ralph Schoon (63.5k●3●36●46)
| answered Jan 06 '21, 3:43 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Jan 11 '21, 4:47 a.m.
In order to be able to use the Chrome (or other browsers) development tools and to debug a Java Script attribute customization, you have to use the infix '?internal=true' in the work item editor url. If this is not added into the url, the javascript is compressed and you won't see it.
e.g. open the work item and change the URI by injecting ?internal=true before the action like this:
https://elm.example.com:9443/ccm/web/projects/JKE%20Banking%20%28Change%20Management%29?internal=true#action=com.ibm.team.workitem.viewWorkItem&id=1
Under sources for the page you should see a tree. The root node is top, then you see a node for the app e.g. elm.example.com:9443.
There should be another node named (no domain) and you should find the script underneath that. You can open it, and set breakpoints.
If you don't see https://jazz.net/library/article/1360 and see https://jazz.net/library/article/1093 the last lab at least.
Comments Ralph,
I did as you directed and injected the "?internal=true" part into the url. I found in the console at the bottom of the sources tab a message reporting an error as follows:
"Problems executing value provider for example.roi.ValueProvider: Cannot load the script class - example.roi.ValueProvider"
And I found this in the ccm.log:
com.ibm.team.rtc.common.scriptengine.UnknownTypeException: 'example.roi.ValueProvider' is not a constructor
Do you by chance know what causes this error/how to correct it?
Ralph Schoon
commented Jan 14 '21, 2:19 a.m.
| edited Jan 14 '21, 2:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Here are my 2 cents, Timothy. If the script is so messed up that it would not even load, it is likely an issue of encoding, line endings or invalid character sets.
You can try to edit the script in an external editor and change to UTF-8 etc...
Initially I would suggest you create a new calculated value script and let the editor fill in the example. Check that you can see the script in debugging and then start from there.
I assume you enabled attachment scripts in the server settings.
Davyd Norris
commented Jan 14 '21, 6:06 p.m.
OK now we are getting somewhere - this means either the script won't compile because there's an error in the code somewhere, or that the name of the script doesn't match.
Can you provide a screen shot of the code as it is in the Eclipse UI? I want to see that all the names match up correctly.
Timothy Distel
commented Jan 20 '21, 12:26 p.m.
Davyd,
I appreciate your persistence in helping with this, Ralph as well. For the record, I am able to see the .js file in the sources of developer tools in chrome, I'm just not proficient enough in debugging to know what to do here to troubleshoot. Also, for some reason I'm now getting something different in the developer tools console:
"Problems loading script example.roi.ValueProvider
[object Object]
// calculate-roi.js"
Here is the screenshot of the code in the Eclipse UI:
|
Ralph Schoon (63.5k●3●36●46)
| answered Jan 21 '21, 3:08 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER edited Jan 21 '21, 3:10 a.m. My last effort.
1. Create a new calculated value, fill in the example, then change the name and add your code. Ideally paste the old code into notepad++ and copy from there.
2. Configure the provider and the dependencies e.g. the complexity
3. Debug in Chrome using ?debug=true in the URI e.g. https://elm.example.com:9443/ccm/web/projects/JKE%20Banking%20(Change%20Management)?debug=true#action=com.ibm.team.workitem.newWorkItem&type=com.ibm.team.apt.workItemType.story&ts=16112154556490 . Set a breakpoint and step through.
4. I admire the courage to just calculate along, however, my experience shows it is better to not make all the assumptions. Use code like mine above to find out what you really get.
5. Add error handling. Calculated attributes are for the attribute, regardless which work item type in the project area that uses it. Make sure to handle the cases for no complexity or no business value.
|
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.