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
dojo.provide("com.bay.ExemptionReasonValidator");

dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes")
    (function () {
        var Severity = com.ibm.team.workitem.api.common.Severity;
        var Status = com.ibm.team.workitem.api.common.Status;
        var WorkItemAttributes = com.ibm.team.workitem.api.common.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.
Regards,
Derm Phongninlaarphon

One answer



permanent link
Ralph Schoon (63.1k33646) | answered Aug 26 '22, 4:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Aug 26 '22, 4:22 a.m.
  1. I would suggest you look at https://jazz.net/library/article/1093 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. https://elm.example.com:9443/ccm/web/projects/ACME%20Development%20%28Change%20Management%29?debug=true#action=com.ibm.team.workitem.newWorkItem&type=com.acme.wi.type.custrequest&ts=16615010758610 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.


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.