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

Script Fails to run at all.

I have a Modified Date initiated script that does not give us any output to the Console. It is a calculated value. We are calling script from a Workitem Attribute that is a small-string data type, but we can't get any response from the script once it is called.  Can someone please help?

// The script name must be the same in lines 1 and 8.
// This script needs to be modified to make it stop calculating when the state is set to "closed"
dojo.provide("org.example.calculated.AgeValueProvider");
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("org.example.calculated.AgeValueProvider", null, {

    getValue: function(attribute, workItem, configuration) {
      var creationDate = fromISOString(workItem.getValue(WorkItemAttributes.CREATION_DATE));
                  var resolutionDate = fromISOString(workItem.getValue(WorkItemAttributes.RESOLUTION_DATE));
                                console.log("creation date" + creationDate);
                                console.log("Resolution date" + resolutionDate);
                  if(resolutionDate !== null){
                                var ageInSeconds = (resolutionDate.getTime() - 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";
                                 
                  }else{
                               
        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 "";
    }
  });
})();

0 votes

Comments

You should be able to use a debugger or look at the logs to get an idea. See Process Enactment Workshop for the Rational solution for Collaborative Lifecycle Management Lab 5


Accepted answer

Permanent link
Hi, Kenneth

I tested with v5.0.2 with your javascript(add a small string attribute for the calculated value)



what version did you test with and what result did you get?
Kenneth Herrscher selected this answer as the correct answer

0 votes


2 other answers

Permanent link
It may be a silly mistake - you said the script is "Modified Date initiated", but the script reads Resolution Date. Make sure that you make the dependency right.

Another thing to note - you should also check the null value for variable "creationDate", as it will be definitely null during the creation of a new work item.

0 votes

Comments

Good answer.  We did change this script so that it stopped counting seconds after the Resolution (close) date was entered. It's working fine now.


Permanent link
Actually the correct answer was how to get any of the scripts to run for a workitem and a project.   What solved it was we found a script entry         /workitem/scripts/common/sar_warranty.js     that had zero bytes.  We found that  condition causes no scripts to run for the entire project.  We deleted this zero byte script file and everything began to work again.  That smells like a bug to me.



0 votes

Comments

I did see such behavior before, and it is quite easy to spot using a debugger. The JavaScript engine appears to evaluate all the scripts as a whole, and a single corrupted script can render all scripts invalid. Regarding your original issue, you described it in a way that made us believe only the one quoted script didn't work. How can you expect a "correct" answer for such a question then?

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: Mar 31 '16, 5:16 p.m.

Question was seen: 2,517 times

Last updated: Apr 05 '16, 8:09 p.m.

Confirmation Cancel Confirm