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

Calculated Value not working

I have a script to calculated value bases on 2 other attributes.  When I change either of the 2 attributes, nothing happens. any ideas, here is the script: we are on 6.0.1 ifix 003

dojo.provide("com.ce.team.workitem.attribute.riskProbabiltyCostProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
    dojo.declare("com.ce.team.workitem.attribute.riskProbabiltyCostProvider", null, {

    getValue: function(attribute, workItem, configuration) {

        try {
            var consequenceCost = parseInt(workItem.getValue("com.ibm.team.workitem.workItemType.risk.consequencecost"));
            var probabilityAttribute = configuration.getChild("probabilityAttribute").getIdentifier()
            var probability = this.__getLastIntSegment(workItem.getValue(probabilityAttribute));
            var calcCost = (consequenceCost * probability) / 100
            return calcCost.toString();
        }
        catch(err) {
            var txt;
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            txt+="Click OK to continue.\n\n";
            alert(txt);
        }

    }, //end getvalue

     __getLastIntSegment: function(identifier) {
      if (identifier != null) {
         var lastSeparator = identifier.lastIndexOf('.');
         var numberString = identifier.substring(lastSeparator+2);
         return parseInt(numberString, 10);
      }
      return -1;
    },

    __sentinel: null

    });
})();

0 votes


Accepted answer

Permanent link
 Found the issues we were having
1. forgot to establish the dependencies for thecalculated value, hence it was never firing.
2. get child was not working, so we changed code to:
dojo.provide("com.ce.team.workitem.attribute.riskProbabilityCostProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
    dojo.declare("com.ce.team.workitem.attribute.riskProbabilityCostProvider", null, {

    getValue: function(attribute, workItem, configuration) {

        try {
            //console.log("Executing cost provider");
            var consequenceCost = parseInt(workItem.getValue("com.ibm.team.workitem.workItemType.risk.consequencecost"));
            //console.log("Cost = " + consequenceCost);
            var probabilityAttribute = workItem.getLabel("com.ibm.team.workitem.workItemType.risk.probability");
            //console.log("Prob Enum: " + probabilityAttribute);
            var probability = this.__getLastIntSegment(probabilityAttribute);
            //console.log("Probability: " + probability);
            var calcCost = (consequenceCost * probability) / 100;
            return calcCost.toString();
        }
        catch(err) {
            var txt;
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            txt+="Click OK to continue.\n\n";
            console.log(txt);
        }

    }, //end getvalue

     __getLastIntSegment: function(identifier) {
      if (identifier != null) {
         var lastSeparator = identifier.lastIndexOf('%');
         //console.log("Sep index: " + lastSeparator);
         var numberString = identifier.substring(0,lastSeparator);
         //console.log("Number: " + numberString);
         return parseInt(numberString, 10);
      }
      return -1;
    },

    __sentinel: null

    });
})();
We now have it working, thanks for all the feedback.
Ralph Schoon selected this answer as the correct answer

0 votes


2 other answers

Permanent link
 Did you update the application to allow process attachment scripts to run?  

  1. Go to the administrative page of your RTC server https://your.server.name:9443/ccm/admin
  2. Open the Server tab
  3. From the left side-bar open Configuration > Advanced Properties
  4. In the Work Item Component find the Enable Process Attachment Scripts property and set its value to true
  5. Save your changes

0 votes

Comments

Thanks, This was the first thing we did. 

and still nothing, how can we tell if it is firing?? 


Permanent link
The use of configuration.getChild() looks suspicious. Make sure that you did not make the same mistake as in this post. Basically, if you need to use "configuration", you need to make changes in the process configuration source accordingly.
https://jazz.net/forum/questions/219896/i-want-to-use-a-calculated-field-to-sum-an-attribute-from-all-children

Secondly, if you make any mistakes in the script, the function __getLastIntSegment() will always return -1. Whether it's visible to you or not, I'm not sure.

Thirdly, make sure you have configure the target attribute to be dependent on the other two attributes, which brings up a messy issue - why can't you use the Id of "probabilityAttribute" in the script? It should be static anyway, otherwise you cannot set it in the Depends On field of the target attribute.

And finally, use console.log() to debug your code. Don't use alert(), as it may only work in a browser, but the script can run in a browser, Eclipse and on the server. And check the server log file and browser web console - this funny looking script may render all the JavaScript script useless (RTC seems to evaluate all scripts as a whole).

0 votes

Comments

I think the, incorrect, assumption of the author is that configuration.getChild() somehow provides access to a child work item.

I don't think it makes sense to try to debug scripts in the forum. Especially if there is no information what the script is supposed to do.

See

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,116

Question asked: Apr 18 '16, 4:49 p.m.

Question was seen: 3,042 times

Last updated: Apr 19 '16, 12:31 p.m.

Confirmation Cancel Confirm