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

custom attribute script concatenates instead of adding

My script works fine with eclipse client but with webclient the numbers are getting concatenated instead of adding.
This script was working fine until I added on extra addition toward the end of the script.

ojo.provide("CalculateHLDSizing");

var f = function() {
    dojo.declare("CalculateHLDSizing", null, {
          getValue: function(attributeId, workItem, configuration) {
                 var result = workItem.getValue("hldArchitectureHours") +
                workItem.getValue("hldDeploymentHours") +
                workItem.getValue("hldmacroDesignHours") +
                workItem.getValue("hldAPIhours")+
                workItem.getValue("hldGUIHours")+
                workItem.getValue("hldInputETLHours")+
                workItem.getValue("hldCoreDBHours")+
                workItem.getValue("hldReportsHours")+
                workItem.getValue("hldOutputETLHours")+
                workItem.getValue("hldUATHours")+
                workItem.getValue("hldSystemTestHours") +
                workItem.getValue("hldDocumentationHours") +
                workItem.getValue("hldTrainingHours") +
                workItem.getValue("hldASCAHours");
            return result;
        }
    });
};

f();

0 votes


Accepted answer

Permanent link
JavaScript is kind of weird (from my perspective). When creating the Process Enactment Workshop for the Rational solution for Collaborative Lifecycle Management 2012, I realized that it might treat things as string where I wanted integer. In Lab 5.2 I used parseInt() to convert strings to integer and then add the data.
Kiran Poovaiya selected this answer as the correct answer

0 votes

Comments

Thankss , this helped , I added parseInt around the values and it worked like a charm.
                var result = parseInt(workItem.getValue("architecture_hr_rom")) +
                  parseInt(workItem.getValue("macroDesignROMHours")) +
                  parseInt(workItem.getValue("romDeploymentHours"))+
                      .....          parseInt(workItem.getValue("romASCAHours"));
            return result;
   


One other answer

Permanent link
So the underlying thing seems to be that one of your attributes is of type string.

Its most likely the ones which you added latest and soon after started noticing the concatenation.
So, I would suggest reviewing the the types of the attributes.

Here is something more to make it easier to follow:

Below is a script that runs on
-  two Integer attributes (firsthours_int, secondhour_int) and
-  a string attribute (thirdhour_str). 

As long as I use the values read from Integer attributes, the return is an Integer
As soon as I start using the "thirdhour_str", the return is a concatenated one.

dojo.provide("com.example.sumitup");

(function() {
    dojo.declare("com.example.sumitup", null, {

        getValue: function(attribute, workItem, configuration) {

var fh = workItem.getValue("firsthours_int");
var sh = workItem.getValue("secondhour_int");
var th = workItem.getValue("thirdhour_str");

var sum = fh + sh + th;  //returns a concatenated of (sum of fh and sh) and th
var sum = fh + sh;  // returns an integer

return sum;

        }
    });
})();

Like Ralph already pointed out, your solution is in using parseInt() when working with strings. 
However, I believe instead of Integer attributes, you have gotten a string typed attribute which is causing the failure for you.

Hope this helps.

1 vote

Comments

Great answer Dinesh, I was deliberately using String type attributes in my example to be able to specify 1w for one week.

thanks Ralph :)

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
× 10,937

Question asked: Sep 24 '13, 1:46 a.m.

Question was seen: 4,404 times

Last updated: Sep 24 '13, 7:15 a.m.

Confirmation Cancel Confirm