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

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

 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!

0 votes



2 answers

Permanent link
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.

0 votes

Comments

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.


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
 I figured it out.
I for some reason thought that recursion was not allowed in rtc.

But this fixed my problem

0 votes

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
× 6,121
× 1,700
× 457
× 152
× 4

Question asked: Jul 13 '16, 1:55 p.m.

Question was seen: 3,716 times

Last updated: Jul 18 '16, 1:34 p.m.

Confirmation Cancel Confirm