How to calculate value of attribute type Duration in RTC worktiem.
2 answers
A simple add of those values in Script Based Calculated Value seems to do the trick, unless i totally missed your requirement...
here is a sample code for the script :
var varDura1 = workItem.getValue('dura1');
var varDura2 = workItem.getValue('dura2');
var duraSum = varDura1 + varDura2;
return duraSum;
var varDura2 = workItem.getValue('dura2');
var duraSum = varDura1 + varDura2;
return duraSum;
dojo.provide("com.example.toatEstimation");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
dojo.declare("com.example.toatEstimation", null, {
getValue: function(attribute, workItem, configuration) {
try {
var reqtimeEst = getAttributeData(workItem.getValue("reqtimeestimated_new"));
var arctimeEst = getAttributeData(workItem.getValue("archtimeestimated_new"));
var timeEst = getAttributeData(workItem.getValue("timeestimated_new3"));
var timeEst;
timeEst = reqtimeEst + arctimeEst
return timeEst.toInt();
}
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);
}
}
});
Comments
i see a few issues with this code :
1. redundant call :
var timeEst = getAttributeData(workItem.getValue("timeestimated_new3"));
just the declaration as below is sufficient.
var timeEst;
2. where do you define "getAttributeData"??
This call also looks redundant., you could read the getValue on attribute id, directly into a var
3. in my case, .toInt() was not required
and lastly, please add some comments on what you see / not see from the sample code you present above... right now its open for assumptions and you may not get the right answer soon enough...
Yes Dinesh,
Its not working for me. I think this issue is related to con-cad When we do get attribute,data, the variable holds string i,e. '5' 'hours'
and while passing value it is not understanding 'hours' I think split function will be needed. could you please help me to split this with the help of array. I am new to JS.
Kind regards,
Krunal.
If you do a getValue on an attribute of type Duration you should get a number and not anything with hours.
I have been usually able to find information about programming languages in the internet. You should search the internet for questions related to Java Script.
You can find the few of my (terrible) knowledge about Java Script in this context here: https://jazz.net/library/article/1093
Don't use alert, use console.log().
You can debug scripts, see https://jazz.net/library/article/1360