Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference qualifier not working as expected when Assigned To is cleared

tilekarnilesh
Giga Guru


Hello ,

I’m working on a Change Task (CTASK) form where we have three user reference fields:


Assigned To-

tilekarnilesh_0-1758637443404.png

 

Change Observer--

tilekarnilesh_1-1758637491433.png

 

Change Reviewer-->

tilekarnilesh_2-1758637568437.png

 

The requirement is that the same person cannot be assigned to multiple fields.
So, for example, if a user is selected as the Change Reviewer, they should not appear in Change Observer or Assigned To, and vice versa.

This works fine when I first choose Assigned To, and then select the other fields — it correctly prevents duplicates.

The issue:

If I first select Change Reviewer or Change Observer, and then try to select Assigned To, the same user is still available to pick.

Thanks in advanced.😊

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@tilekarnilesh 

advanced ref qualifier looks fine to me.

another way is to use onSubmit client script and check this

function onSubmit() {
    var user1 = g_form.getValue('u_change_reviewer'); // Replace with your field names
    var user2 = g_form.getValue('u_change_observer');
    var user3 = g_form.getValue('assigned_to');

    // Check for repeats among the three reference fields
    if ((user1 && user1 == user2) ||
        (user1 && user1 == user3) ||
        (user2 && user2 == user3)) {
        g_form.addErrorMessage('Only unique users are allowed');
        return false; // Prevent submission
    }

    return true; // Allow submission
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

GlideFather
Tera Patron

Hi @tilekarnilesh,

 

you will might need to achieve this with onChange client script

_____
This reply is 100 % GlideFather and 0 % AI

@GlideFather How??

@tilekarnilesh it will be 3 client scripts one for each field and you will add conditions that each of the field is changed, then it will checked the values in the other two

 

Navigate to: The GlideForm (g_form) Class and check for getValue()

 

_____
This reply is 100 % GlideFather and 0 % AI

Hi @tilekarnilesh 

 

Please test your requirement with the above code and screenshot that i have shared and let me know .

 

if my response is helpful please mark as helpful and accept the solution

 

Thank you!!