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

Attribute customization scripts / Calculated Values Scripts

I am trying to calculate the time duration between Creation date and current date. SO it means i want to calculate Task Time duration and show it on work item
My code is not mapping it on work item Presentation

dojo.provide("com.rc.TaskDuration");
dojo.require("dojo.date");
dojo.require("dojo.date.stamp");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
  dojo.declare("com.rc.TaskDuration", null, {

    getValue: function(attribute, workItem, configuration) {
      var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
      if (creationDate) {
        var ageInSeconds = (Date.now() - creationDate.getTime()) / 1000;

        var days         = parseInt(ageInSeconds / 86400);
        var hours        = parseInt((ageInSeconds-days * 86400) / 3600);
        var minutes      = parseInt((ageInSeconds-days * 86400 - hours * 3600) / 60);
               
        return days + " d, " +  hours + " hr, " + minutes  + " min";
      }
      return "";
    }
  });
})();

As i am mapping it with a variable of type Long.
Please give me any solution.

0 votes


Accepted answer

Permanent link
This is most likely a code problem. As Tiago already answered, you return a String and not a long. I would assume you use an attribute of type duration. 

Try with a simple provider and check what the value of such a duration attribute is.
Try with a simple provider that returns a long all the time. If that works, go from there.

      return days + " d, " +  hours + " hr, " + minutes  + " min"; 

Is a string and not a long. If you want to show that, use a string attribute.
If you want to show a duration attribute remove the characters and, if in doubt use parseInt() or some other method to return the long value.
Salman Shaikh selected this answer as the correct answer

1 vote

Comments

I am not even getting value when just i try to post creation Date against my attribute with Type Timestamp/ Date.
I mean to say that no value is pointed at work item presentation.

What do you expect to see in the presentation if you return no data or the wrong type?

What ever just wanted to see if something is come into presentation even it can be static value.

You have to return a value that is compatible with the value of the attribute, otherwise all you will see is an error in the log. Consider going through Process Enactment Workshop for the Rational solution for Collaborative Lifecycle Management the RTC only version.

1 vote


One other answer

Permanent link
 You are returning a String, not a Long! 

1 vote

Comments

But still i am not getting value mapped on Work item. It is showing nothing in value.

Do you added the creation date as an dependent attribute?


If you return a fixed string, your calculated value works? Maybe your problem is some bug in your code, and not on calculated value configurations itself.

1 vote

Yeh, i already set Creation date as dependency,
and it is not even showing static string output.

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

Question asked: Jun 18 '15, 9:42 a.m.

Question was seen: 2,958 times

Last updated: Jun 22 '15, 10:42 a.m.

Confirmation Cancel Confirm