Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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. 

0 votes



2 answers

Permanent link
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;

0 votes

Comments

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

yes Ralph, its milliseconds.,


Permanent link

 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); 
        }
 
    }
 
    });

0 votes

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

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,951

Question asked: Apr 13 '20, 5:01 a.m.

Question was seen: 2,059 times

Last updated: Apr 17 '20, 2:09 p.m.

Confirmation Cancel Confirm