How to calculate value of attribute type Duration in RTC worktiem.
Hi team,
I have two attributes called "Requirement Estimation" and "Development Estimation" and the attribute type is duration for both the attribute. How do i calculate total Estimation using Java scrip.
Could you please help me on this?
Kind regards,
Krunal.
|
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; Comments Duration is milliseconds if I am not mistaken, so I think you are right.
yes Ralph, its milliseconds.,
|
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 :
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.
Ralph Schoon
commented Apr 17 '20, 12:22 p.m.
| edited Apr 17 '20, 2:09 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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
|
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.