It's all about the answers!

Ask a question

How to correct my Script Based Validator?

Derm Phongninlaarphon (151) | asked Aug 26 '22, 2:59 a.m.

 I'm Trying to write a script based validator but it didn't work out.

here is my code

    (function () {
        var Severity =;
        var Status =;
        var WorkItemAttributes =;
        dojo.declare("com.bay.ExemptionReasonValidator", null, {
            validate: function (attributeId, workItem, configuration) {
                if ((workItem.getValue("com.bay.task.attribute.sit_exempt02") === "com.bay.task.enumeration.sit_exempt01.literal.l2") && (workItem.getValue("com.bay.task.attribute.exemption_reason02") === "")) {
                    return new Status(Severity["ERROR"], "Validation failed");
                } else {
                    return Status.OK_STATUS;
I want to validate when workItem.getValue("com.bay.task.attribute.sit_exempt02" === "com.bay.task.enumeration.sit_exempt01.literal.l2") >>> literal.l2 is YES

this attribute must not be empty (workItem.getValue("com.bay.task.attribute.exemption_reason02") === ""))
if it empty it shouldn't be able to save and show error.

Please help me with this code.
Derm Phongninlaarphon

One answer

permanent link
Ralph Schoon (62.7k33643) | answered Aug 26 '22, 4:16 a.m.
edited Aug 26 '22, 4:22 a.m.
  1. I would suggest you look at for some inspiration. Since you have your unique process configuration, I  do not see what the forum could do. 
  2. Keep in mind that the validation requires the operation behavior configured
  3. I have never had the self-confidence to create an if statement like you do, without using intermediate variables. If you use intermediate variables continue to the next step.
  4. Use Chrome and inject ?debug=true into the work item URI before the first # e.g. then open the Developer Tools open your script under Sources, no domain and use the debugger.

   PS: This should work with other browsers, but I always struggle to find my scripts in Firefox for example. Chrome works best for me.

Your answer

Register or to post your answer.