It's all about the answers!

Ask a question

Script Based validator: error not preventing work item from Save


Don Yang (7.7k21114139) | asked Jul 10 '23, 10:54 p.m.

EWM 7.0.2 ifix022 


1) Add the below javascript to Eclipse client's Validator

dojo.provide("com.reappearRate.Validator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity= com.ibm.team.workitem.api.common.Severity;
var Status= com.ibm.team.workitem.api.common.Status;
    dojo.declare("com.reappearRate.Validator", null, {
        validate: function(attribute, workItem, configuration) {
var aa = workItem.getValue(attribute);
if(aa!=''){
let checkValue = aa.match(/\d+\/\d+/g);
if(!checkValue){
return new Status(Severity["ERROR"], "Incorrect Format, Fraction expected!"); 
}else{
return Status.OK_STATUS;
}
}else{
return Status.OK_STATUS;
}
        
        }
    });
})();

2) add a new small string attribute to Defect or task type working and set the Validator as above
3) configure precondition "Attribute Validation" for Everyone role of Save work item
4) create a new work item and enter invalid "111" or "test" to the custom attribute and an error indicator showing up and the messages are correct when hovering on it. If it is "4/5" is entered, no error showing up, which seems that javascript works as expected
5) when there is error entry, I can still save the work item which is not Expected behavior as precondition is configured for everyone role.

There are similar discussions in the past such as

most of them suggested to check with unused javascript etc. In the environment, this is the only one javascript at this moment so that should not be a problem.
ccm.log shows:
[Default Executor-thread-1501 @@ 18:13 ibm <Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36@9.43.207.142> /ccm/service/com.ibm.team.workitem.common.internal.rest.IWorkItemRestService/workItem2] ERROR com.ibm.team.workitem.common                       [TID: 8AF13114] - Error invoking validator reappearRate associated with the attribute 'ErrorRate' in the project area with id '_AuS80Ci1Ee2p-5CTlLaGBw'.You can link to the project area definition using a URL similar to https://thehostname:9443/jazz/process/project-areas/_AuS80Ci1Ee2p-5CTlLaGBw, where the host name, port and jazz context are configured for your installation. Contact your project area administrator for assistance.
com.ibm.team.rtc.common.scriptengine.UnknownTypeException: 'com.reappearRate.Validator' is not a constructor

I am wondering what else could be wrong.
Many thanks.

One answer



permanent link
Ralph Schoon (63.3k33646) | answered Jul 11 '23, 1:45 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

 I don't know, what is going on. I have done this and it has worked for me in the past.

What you can do:

1. Try to use the debugger to check your script works. I think it does.
2. Make the script easier to understand. Have a default return OK_STATUS and only return error when you need to. This just makes it easier to understand.
3. Understand https://jazz.net/library/article/292 and make sure there is a configuration of the operation behavior for every role that has operation behavior configured. If there is only behavior configured for the everyone role, you should be fine, if there are other roles configured, make sure to add the operation behavior configuration there as well.
4. Make sure to use another browser and another user to try it out. Close the browser and open it again. 

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.