Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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?

0 votes



3 answers

Permanent link
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

0 votes

Comments

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?

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



0 votes

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?

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.

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.

 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

 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.



0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 6,121

Question asked: Dec 28 '20, 9:17 a.m.

Question was seen: 1,807 times

Last updated: Jan 21 '21, 3:10 a.m.

Confirmation Cancel Confirm