It's all about the answers!

Ask a question

I can capture a date via javascript but it goes away after the condition is no longer met?


Daniel Flores Montanez (19813) | asked Jul 13 '16, 1:55 p.m.
 I have a code that captures the date via javascript.
Something like:
dojo.provide("com.example.inprogressdate");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.example.inprogressdate", null, {
    getValue: function(attributeId, workItem, configuration) {
        var currentDate = 0;    
        var inProgressStatus = workItem.getValue(WorkItemAttributes.STATE);  
        var verifyTaskState = "com.ibm.team.workitem.taskWorkflow.state.s2";
        if (inProgressStatus == verifyTaskState){ 
               currentDate = Date.now();  
               return currentDate.toString();
        }
}  }
});
})();

This captures the date
But once the workflow goes from s2 to s3 then the date disappears.

I've tried
"return currentDate;" right after if statement closes, This makes the date stick, but because there's an error: 
java.lang.NumberFormatException: For input string: "0.0"
because 0 cant be a timestamp and this won't work for a solution because it'll plague my log file withe rrors
I've tried
"return currentDate.toString()" but that overwrites the current time with the default timestamp value of 0. 

Any help would be awesome!
Ideally I'd want for the attribute to simply store and keep the first input it gets!

2 answers



permanent link
Ralph Schoon (63.1k33645) | answered Jul 14 '16, 2:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jul 14 '16, 3:02 a.m.
The error is due to the fact that you have written an invalid script. The script is a function, but only returns a value if the condition is met. There is no global return if the condition is not met. Your log should show errors all over the place.

Unfortunately you can write as many incorrect scripts as you like and the JavaScript development environments usually don't show you even these primitive errors. That is why I don't like JavaScript. The environments are not supporting enough. You could not have compiled a Java class with such an error. Development is not getting easier and better supported, it is getting harder and development goes back to the 1980's using printf to debug.

You have to carefully read https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript to understand how to convert the dates to make them meaningful in RTC.

Comments
Daniel Flores Montanez commented Jul 14 '16, 10:10 a.m.

the problem is that i could make it return something if the condition is not met, but I don't want that because once the condition is not met, the return will overwrite the timestamp I want.


and I can't return a null or random integers, because that's not allowed in a timestamp. As I said java.lang.NumberFormatException

so how can I make it so that the return if there's no condition met, does nothing. It doesn't overwrite the data if the condition was met prior... it just does nothing.



Ralph Schoon commented Jul 14 '16, 10:15 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

A function HAS to return a value whether you want or not. Not returning anything is not an option. You can read the attribute value and return the original value if you don't want to change it.


permanent link
Daniel Flores Montanez (19813) | answered Jul 18 '16, 1:34 p.m.
 I figured it out.
I for some reason thought that recursion was not allowed in rtc.

But this fixed my problem

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.