It's all about the answers!

Ask a question

Attribute customization scripts / Calculated Values Scripts


Salman Shaikh (23413875) | asked Jun 18 '15, 9:42 a.m.
edited Jun 18 '15, 10:56 a.m. by Ralph Schoon (63.6k33646)
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.

Accepted answer


permanent link
Ralph Schoon (63.6k33646) | answered Jun 18 '15, 11:06 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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

Comments
Salman Shaikh commented Jun 18 '15, 11:23 a.m.

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.


Ralph Schoon commented Jun 18 '15, 11:57 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


Salman Shaikh commented Jun 22 '15, 7:33 a.m.

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


1
Ralph Schoon commented Jun 22 '15, 10:42 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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.

One other answer



permanent link
Tiago Moura (8537) | answered Jun 18 '15, 9:53 a.m.
 You are returning a String, not a Long! 

Comments
Salman Shaikh commented Jun 18 '15, 10:07 a.m.

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


1
Tiago Moura commented Jun 18 '15, 10:12 a.m.

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.


Salman Shaikh commented Jun 18 '15, 10:36 a.m. | edited Jun 18 '15, 10:36 a.m.

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

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.