Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Script-based validator runs 3 times on a save?

I have a semi-simple script-based validator, which I have set on both the OwnedBy and the FiledAgainst attributes on a task.  I (eventually) will do validation that if OwnedBy is not Unassigned (so someone owns it), the FiledAgainst attribute can not be "Backlog" (which is our default which means it isn't in any team yet).

I have the script written and running.  I have confirmed that it only runs when I change one of the two fields (FiledAgainst or OwnedBy) and not when things like Priority are changed, which is good.

However, if I change JUST the OwnedBy attribute and click Save, it looks like my Script is run 3 times, based on the console.log messages that I have in the script.  As it starts, I log the values of the 2 attributes, and then if the OwnedBy is Unassigned (based on the UUID), I log a 3rd message.  I did a single save of just changing the OwnedBy attribute and you can see, I get 3 sets of my 3 message lines.  Is there a reason why it runs 3 times???

the Log messages:
!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:45.513
!MESSAGE LOG: _YNh4MOlsEdq4xpiOKg5hvA

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:45.517
!MESSAGE LOG: _jMF98OkHEeKDodPdruloFA

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:45.522
!MESSAGE LOG: Unassigned Owner

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:46.554
!MESSAGE LOG: _YNh4MOlsEdq4xpiOKg5hvA

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:46.557
!MESSAGE LOG: _jMF98OkHEeKDodPdruloFA

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:46.561
!MESSAGE LOG: Unassigned Owner

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:47.394
!MESSAGE LOG: _YNh4MOlsEdq4xpiOKg5hvA

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:47.398
!MESSAGE LOG: _jMF98OkHEeKDodPdruloFA

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2013-07-10 14:02:47.402
!MESSAGE LOG: Unassigned Owner


The script:
dojo.provide("com.ibm.ws.team.rtc.attribcustom.validators.CheckFiledAgainst");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("com.ibm.team.workitem.api.common.Status");

(function() {
    var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
    var Status= com.ibm.team.workitem.api.common.Status;
       dojo.declare("com.ibm.ws.team.rtc.attribcustom.validators.CheckFiledAgainst", null, {

    validate: function(attributeId, workItem, configuration) {
        console.log(workItem.getValue(WorkItemAttributes.OWNER));
        console.log(workItem.getValue(WorkItemAttributes.FILED_AGAINST));
       
        //Note:  OwnedBy=Unassigned maps to UUID _YNh4MOlsEdq4xpiOKg5hvA
        var unassignedOwner = "_YNh4MOlsEdq4xpiOKg5hvA";
        if (workItem.getValue(WorkItemAttributes.OWNER) === unassignedOwner) {
            console.log('Unassigned Owner');
            return Status.OK_STATUS;
        }
       
        else {
                    console.log('validate here!');
                //var severity= configuration.getChild("parameters").getStringDefault("severity", Severity.ERROR.name);
                //var message= configuration.getChild("parameters").getStringDefault("message", "");
                //return new Status(Severity[severity], message);
                return Status.OK_STATUS;
            }
    }
});
})();

0 votes

Comments

And a follow-on ... once I finally get down to setting the message (which I have no done)
var severity = "ERROR";
var message = "A work item owned by an individual must be Filed Against that person's team backlog.";
return new Status(Severity[severity], message);

I see the little red 'x' next to the OwnedBy field (good) and if I hover over the 'x' I get my message (good) .... how do I get it to show up at the top of the work item so it kinda slaps the user in the face (so to speak)??

Susan


Accepted answer

Permanent link
Hi Susan, I have also seen that the validation scripts fires more than once and I guess some internal events or probably the value change in attributes with dependencies are triggering them. Either way I don't think that is harmful.

To show the error message at the top, I think you have to add the "Attribute Validation" precondition from Team configuration -> Operation Behavior -> Save WorkItem (Server)
Susan Hanson selected this answer as the correct answer

0 votes

Comments

Right Indradri and a save is also only prevented if the Icon is set to error. See https://jazz.net/library/article/1093 Lab 4. 

SWEET!!  I have it all working now and it is AWESOME!

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Jul 10 '13, 2:08 a.m.

Question was seen: 3,720 times

Last updated: Jul 10 '13, 5:24 a.m.

Confirmation Cancel Confirm