script for adding two attributes in RTC
I have created 3 customized attributes in rtc (attrib 1, attrib 2, attrib 3) for the task workitem type. The datatype for all the 3 is Integer.
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.
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
one more way to do the same:
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;
}
});
})();
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
I think I have posted this very same answer like a few days ago already. However, I wasn't able to find it myself, so here goes again. Make sure to add the other attributes to the dependent list of attributes for the attribute that is calculated.
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);
}
});
})();
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);
}
});
})();
Hi Naveen,
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;
}
});
})();
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
showing 5 of 6
show 1 more comments