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(); |
Accepted answer
Ralph Schoon (63.5k●3●36●46)
| answered Sep 24 '13, 3:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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
Comments
Kiran Poovaiya
commented Sep 24 '13, 7:15 a.m.
Thankss , this helped , I added parseInt around the values and it worked like a charm.
|
One other answer
Dinesh Kumar B (4.1k●4●13)
| answered Sep 24 '13, 4:56 a.m.
JAZZ DEVELOPER edited Sep 24 '13, 4:59 a.m.
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"); 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. 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
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.