It's all about the answers!

Ask a question

How to calculate value of attribute type Duration in RTC worktiem.

Krunal Gaoli (67869) | asked Apr 13 '20, 5:01 a.m.

 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, 

2 answers

permanent link
Krunal Gaoli (67869) | answered Apr 14 '20, 7:04 a.m.


 (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";

Dinesh Kumar B commented Apr 14 '20, 8:29 a.m.

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...

Krunal Gaoli commented Apr 17 '20, 8:08 a.m. | edited Apr 17 '20, 8:25 a.m.

 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, 

Ralph Schoon commented Apr 17 '20, 12:22 p.m. | edited Apr 17 '20, 2:09 p.m.
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:

Don't use alert, use console.log().

You can debug scripts, see

permanent link
Dinesh Kumar B (4.1k413) | answered Apr 13 '20, 11:00 a.m.
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;

Ralph Schoon commented Apr 14 '20, 8:41 a.m.

Duration is milliseconds if I am not mistaken, so I think you are right.

Dinesh Kumar B commented Apr 14 '20, 9:29 a.m.

yes Ralph, its milliseconds.,

Your answer

Register or to post 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.