EWM 7.0 - How to have calculated value script clear a timestamp attribute?
Hello,
The below is the behavior we see for the web client. We are not using Eclipse client.
We have a calculated value script that inserts today's date into an attribute of type Timestamp if the user has checked the box on a Boolean attribute. When the user sets the checkbox (true), the calculated script correctly inserts today's date into the Date attribute. Before saving the work item if the user unchecks the box then, as we want, the Date attribute is cleared.
This works fine. Once. If the user again checks the box (before clicking Save) then we can see that the calculated value script is not even called again (from console.log() ) . So the attribute does not get set to today's date.
It seems the problem is with the return value from the calculate value script if the Boolean is unchecked. The above scenario plays out when we return null. We've tried returning null, "", 0, and even "Undefined."
If we return null then that seems to break it and the script won't run again.
If we return "" or 0 then the date attribute displays Jan 1, 1970 - which would be expected for 0.
"Undefined" gives us "Unsupported value - Undefined" - Yes, we are grasping at straws now.
How can we clear (show blank) a Timestamp attribute in a calculated value script?
Thanks!
-Kevin
Accepted answer
Hi Kevin,
I used this script to test. It was configured against the due date attribute. You enter something in the summary and the script triggers. You can debug this in the web UI. Chrome works best.
/*********** * 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.ValueProvider"); dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");(function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.ValueProvider", null, {
getValue: function(attribute, workItem, configuration) { var val = workItem.getValue(attribute) var old= dojo.date.stamp.fromISOString(val); var date = new Date() var dateString = dojo.date.stamp.toISOString(date, {milliseconds:true, zulu:true}); var aSummary = workItem.getValue(WorkItemAttributes.SUMMARY); if(aSummary.includes("Set")){ return dateString; } if(aSummary.includes("null")){ return null; } if(aSummary.includes("Empty")){ return ""; } return workItem.getValue(attribute); } });
})();
I can confirm your observation that the script is not called after returning null, which actually clears the due date, but the script is no longer called afterwards,
I would suggest to open a case with support.
I used 7.0.2 for the test.