It's all about the answers!

Ask a question

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


Krunal Gaoli (65128) | 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, 
Krunal. 

2 answers



permanent link
Dinesh Kumar B (4.0k413) | answered Apr 13 '20, 11:00 a.m.
JAZZ DEVELOPER
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
Ralph Schoon commented Apr 14 '20, 8:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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

yes Ralph, its milliseconds.,


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

 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
Dinesh Kumar B commented Apr 14 '20, 8:29 a.m.
JAZZ DEVELOPER

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


Register or to post your answer.