It's all about the answers!

Ask a question

Why is this script not returning any Calculated Value


Sivarajah Rajeswaran (15212) | asked May 19 '16, 7:39 p.m.
I have
(1). Created a new Custom Field
(2). I have associated the below script with the Custom Attribute, I created above via the "Calculated Field"
(3). And yet when I make any modification to the WI, the custom field is not being populated as expected

dojo.provide("example.calculated.TotalTimeSpent");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");

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

    getValue: function(attribute, workItem, configuration) {
    
      var creationDate = 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 "X";
    }
  });
})();

5 answers



permanent link
Ralph Schoon (63.1k33645) | answered May 20 '16, 2:31 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Many possible issues
  • Script never gets triggered due to missing dependencies
  • Syntax errors in scrip
  • var creationDate is a string and not a boolean



permanent link
Sivarajah Rajeswaran (15212) | answered May 22 '16, 7:49 p.m.
Hi Ralph,

I have checked the syntax in the script, I have removed the "If Creation Date" all together,
I have modified date and Creation date as the dependent attributes and yet the Custom Attribute "TotalTimeSpent" is not getting populated.

I put the fromISOString in front of the call because the exact same script works in another RTC Instance

dojo.provide("example.calculated.TotalTimeSpent");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");

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

    getValue: function(attribute, workItem, configuration) {
    
      var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
  

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

    }
  });
})();

Comments
Ralph Schoon commented May 23 '16, 3:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

It might be a good strategy to start with a simple script that just returns a fixed value, if in doubt. Maybe use some techniques for debugging as described in


Sivarajah Rajeswaran commented May 23 '16, 8:06 p.m.

I tried the simplest of scripts and got the following error in the .log file

Error invoking value provider 'TotalTimeSpent' associated with the attribute 'Total Time Spent' in the project area with id '_8-_jNkaeEeWKd5cSuruh8Q'. You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_8-_jNkaeEeWKd5cSuruh8Q, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance.


Donald Nong commented May 23 '16, 8:15 p.m.

It could be due to syntax errors or other configuration problems. I suggest you remove the Caculated Value completely and start over again.


Sivarajah Rajeswaran commented May 26 '16, 11:46 p.m.

Hi I did that and have the RTC provided script with a constant being returned and still not not return any result

/***********
Licensed Materials - Property of IBM
(c) Copyright IBM Corporation 2011. All Rights Reserved.

Note to U.S. Government Users Restricted Rights: 
Use, duplication or disclosure restricted by GSA ADP Schedule
Contract with IBM Corp.
***********
/
dojo.provide("com.example.TotalTimeSpent");

(function() {
    dojo.declare("com.example.TotalTimeSpent", null, {

        getValue: function(attribute, workItem, configuration) {

return "27/05/16";

        }
    });
})();


permanent link
Sivarajah Rajeswaran (15212) | answered May 23 '16, 8:01 p.m.

Comments
Sivarajah Rajeswaran commented May 26 '16, 11:57 p.m.

Here is the message from the .log file but I am not sure what this means

!MESSAGE Error invoking value provider 'TotalTimeSpent' associated with the attribute 'Total Time Spent' in the project area with id '_8-_jNkaeEeWKd5cSuruh8Q'. You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_8-_jNkaeEeWKd5cSuruh8Q, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance.


permanent link
Sivarajah Rajeswaran (15212) | answered May 23 '16, 8:03 p.m.
I tried the simplest of scripts and got the following error in the .log file



Comments
Ian Wark commented May 30 '16, 2:43 a.m.

 Have you checked that the project area has enabled scripting?


Configuring a script-based customization by attaching a Javascript implementation


permanent link
Sivarajah Rajeswaran (15212) | answered May 30 '16, 5:57 p.m.
Yes Java Scripting is enabled. Here is the error from the log and the script

/*******************************************************************************
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2011. All Rights Reserved.
*
* Note to U.S. Government Users Restricted Rights: 
* Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM Corp.
*******************************************************************************/
dojo.provide("com.example.TotalTimeSpent");

(function() {
    dojo.declare("com.example.TotalTimeSpent", null, {

        getValue: function(attribute, workItem, configuration) {

return "X";

        }
    });
})();





Comments
Ralph Schoon commented May 31 '16, 1:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

You don't have enough reputation to upload images. Consider contacting support. I don't see how we can make progress in the forum. Your project area process might be broken based on what I see.


Ralph Schoon commented May 31 '16, 2:02 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Also the error message is odd. Either there is an issue with accessing the process attachment, or something else is strange. I have not seen this error message and it is not due to a syntax error or a runtime error. The script loading seems to fail already.

Your answer


Register or to post your answer.