script for adding two attributes in RTC
I want the sum of the two attributes (attrib 1, attrib 2) to be displayed automatically in the 3rd attribute (attrib 3). Could you please help me with the required script.
Accepted answer
dojo.provide("org.scripts.addTwoArttibs");
dojo.require("dojo.number");
(function() {
dojo.declare("org.scripts.addTwoArttibs", null, {
getValue: function(attributeId, workItem, configuration) {
var res = 0;
var firstVal = dojo.number.parse(workItem.getValue("rcstlt.ms.firstInt"), {type:'decimal'});
var secondVal = dojo.number.parse(workItem.getValue("rcstlt.ms.secondInt"), {type:'decimal'});
res = firstVal + secondVal;
return res;
}
});
})();
3 other answers
dojo.provide("org.example.workitems.providers.CalcInteger");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.CalcInteger", null, {
getValue: function(attributeId, workItem, configuration) {
console.log("Start..");
var text="";
var out = "Values:\n";
// for integer there should always be a value 0 by default
var aValue = workItem.getValue("calcInputInt1");
text = "Value: " + aValue;
console.log(text);
// for integer there should always be a value 0 by default
var aValue2 = workItem.getValue("calcinputint2");
text = "Value2: " + aValue2;
console.log(text);
// Was: return aValue+aValue2;
// parseInt(addMarginVal)+parseInt(costSavingVal)-parseInt(investVal);
return parseInt(aValue)+parseInt(aValue2);
}
});
})();
please rate the answers if they are useful. String wise I have a similar solution. I can't test it right now. If it concatenates instead of adding, I would search the internet on how java script allows to convert to number or to calculate based on numbers. you would probably also want to add a validation, so that you actually restrict input to valid numbers. My code:
dojo.provide("org.example.workitems.providers.CalcString");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.CalcString", null, {
getValue: function(attributeId, workItem, configuration) {
console.log("Start..");
var text="";
var out = "Values:\n";
var aValue = workItem.getValue("calcinputstring1");
if(aValue=null){
aValue="";
}
text = "Value: " + aValue;
console.log(text);
var aValue2 = workItem.getValue("calcinputstring2");
if(aValue2=null){
aValue2="";
}
text = "Value2: " + aValue2;
console.log(text);
return aValue+aValue2;
}
});
})();
Comments
Thanks Ralph but this script doesen't concatenates either. My scenario is that I have 3 attributes of string data type (attribute4, attribute5, attribute6). I would enter the numeric value in attribute4 & 5. I want the sum of the two to be populated automatically in attribute6.
I agree with you that I need to add a validator as well to ensure that the user enters the no. only.
Naveen,
what do you see?
I have tested this and it worked, as far as I know. You have to make sure to add the attributes 4&5 to the dependent attributes list of attribute 6. What does the log show? I assume you have read https://jazz.net/wiki/bin/view/Main/AttributeCustomization careful and recognized where the different log files are located. You have to enable scripting in the RTC/CCM advanced sttributes. Did you do that?
Ralph before executing the script I made the following changes: 1. changed "calcinputstring1" to "attribute4" and "calcinputstring2" to "attribute5". 2. added the attribute 4 & 5 in the dependency list while creating attribute6. scripting is already enabled becuase the first script is working for me. log:
!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2012-06-18 17:50:22.618 !MESSAGE LOG: Start..
!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2012-06-18 17:50:22.620 !MESSAGE LOG: Value: null
!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2012-06-18 17:50:22.622 !MESSAGE LOG: Value2: null
i can see 0.0 coming by default for attribute 6 and it remains the same after entering the values for attribute 4 & 5.
Hi, i would try to add more console.log statements. I don't see the start for instance. I would suggest to play around with it a little more.
Hi Ralph, The script will work if we comment the IF loop (line 13) and parse the values as integer using parseInt in return function (line 24). Thanks for your help!!!