It's all about the answers!

Ask a question

Calculated value based on enumeration literals


Timothy Distel (73356) | asked Dec 28 '20, 9:17 a.m.

 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



permanent link
Davyd Norris (2.8k217) | answered Dec 29 '20, 10:41 p.m.
edited Dec 30 '20, 5:31 p.m.
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? 


Ralph Schoon commented Jan 05 '21, 2:00 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.

Timothy Distel commented Jan 05 '21, 9:14 a.m. | edited Jan 05 '21, 9:40 a.m.

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());

      return (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.

permanent link
Ralph Schoon (63.5k33646) | 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
Timothy Distel commented Jan 13 '21, 1:29 p.m. | edited Jan 13 '21, 1:39 p.m.

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:


permanent link
Ralph Schoon (63.5k33646) | 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

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


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.