It's all about the answers!

Ask a question

Calculated value based on enumeration literals

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


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


(function() {
  dojo.declare("example.roi.ValueProvider", null, {

    getValue: function(attribute, workItem, configuration) {
      var businessValue = parseFloat(workItem.getValue("businessValue"));
      var points = parseFloat(workItem.getValue("");

      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

Timothy Distel commented Jan 04, 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, 2:00 a.m.
Did you configure the dependencies? See for when scripts trigger.

Also: use Chrome to debug the script.

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


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, 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("");
      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 (57.3k23642) | answered Jan 06, 3:43 a.m.
edited Jan 11, 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:

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.
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 and see the last lab at least.

Timothy Distel commented Jan 13, 1:29 p.m. | edited Jan 13, 1:39 p.m.


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: '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, 2:19 a.m. | edited Jan 14, 2:20 a.m.

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, 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, 12:26 p.m.


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 (57.3k23642) | answered Jan 21, 3:08 a.m.
edited Jan 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.