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

Nawal Singh
Tera Guru

Hi @tilekarnilesh ,

 

I have checked your requirement and tested it in my PDI 

 Here is the code that you need to change-

 

1. Assigned to field Reference Qualifier (advanced) -

 

javascript:
var excludedUsers = [];
if (current.u_change_reviewer) excludedUsers.push(current.u_change_reviewer);
if (current.u_change_observer) excludedUsers.push(current.u_change_observer);

if (excludedUsers.length > 0) {
'sys_idNOT IN' + excludedUsers.join(',');
} else {
'';
}

 

2. In change observer field RQ( advanced)- 

 

javascript:
var excludedUsers = [];
if (current.assigned_to) excludedUsers.push(current.assigned_to);
if (current.u_change_reviewer) excludedUsers.push(current.u_change_reviewer);

if (excludedUsers.length > 0) {
'sys_idNOT IN' + excludedUsers.join(',');
} else {
'';
}

 

3.  In Change reviewer field RQ( advanced) 

 

javascript:
var excludedUsers = [];
if (current.assigned_to) excludedUsers.push(current.assigned_to);
if (current.u_change_observer) excludedUsers.push(current.u_change_observer);

if (excludedUsers.length > 0) {
'sys_idNOT IN' + excludedUsers.join(',');
} else {
'';
}

 

Please change the fields name as per your system configuration

 

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

 

Thank you!!

 

Hi @tilekarnilesh  it should be like the screenshot-

 

NawalSingh_0-1758639660791.png

please test and accept the solution if it work and mark as helpful and accept the solution.

 

Thank you!!

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