How to make custom date field in RTC read- only after user enters a date in it and saves workitem?
We have RTC 5.0.2 with custom Defect workflow. There is a custom date field "Fix Turnover date" with the default value as NONE. We need to make this field required as soon as user enters a date there and clicks Save.
I created a custom script from IBM sample and it made the field as read only for all the preexisting defects with date in the field (which is correct). I added Read Only attribute for Condition for Save action for Everybody under operational behavior.
I tried to create a new defect, saved it and then populated Fix turnover date field and clicked Save. The error message is displayed "Attribute 'Fix Turnover Date' is not modifiable. The 'Fix Turnover Date' attribute is not modifiable".
Then I enter an Alert line in the code to show me how system reads the value in the field. With the Alert line in the code functionality works as it supposed to (meaning it makes the field read-only when I enter a date and then click Save). However, if I comment out Alert link - I am back to having an error message. Is there issue with the script ? Pasting script below. Any help is really appreciated.
dojo.provide("org.condition.readonly");
(function() {
dojo.declare("org.condition.readonly", null, {
matches: function(workItem, configuration) {
var fixTurnoverDate = dojo.date.stamp.fromISOString(workItem.getValue("com.fdc.workitem.attribute.fixTurnoverDate"));
if(fixTurnoverDate != null) {
// alert (fixTurnoverDate);
return true;
}
}
});
})();
3 answers
The obvious problem with the script is that it does not return a value when fixTurnoverDate is null.
Comments
For all I know, conditions can not detect the previous value of an attribute and the current value of the attribute. they only see the current value. As soon as some value is set, it is set for the script. So unless there is an additional information you can use (e.g. a state) to determine when your script should return true, you will not be able to do this. E.g. the best you can achieve is once you actually enter a date, the condition will actually see the date and return true and the attribute will show read-only.
Comments
Thanks to all for help. I found an answer here https://stackoverflow.com/a/5706881
It appeared that page was not ready yet and it worked with alert because alert provided additional timing for the request to go through.
When I added the following "if ( document.readyState !== 'complete' )" statement inside of my code - everything started to work properly.
if(fixTurnoverDate != null) {
if ( document.readyState !== 'complete' )
return;
clearInterval( tid );
}, 100 );
return true;
}