Question on reference qualifier

Mani60
Tera Contributor

Hi All,

 

We have one field in change module form 'u_peer_approver', we are using group member as an reference for that field in configuration dictionary. But while using this we are getting multiple users records when we type any user name in the peer approver field but it should show one one record of the respective user which we are typing or searching for. to resolve this we are using Advanced reference qualifier and we are using below code for that but it is not working for us. Could anyone help me on this.

 

Please find below code which we are using.

 

var uniqueUsers = new Set();
var searchTerm = current.getDisplayValue('u_peer_approver');


var grUser = new GlideRecord('sys_user');
grUser.addQuery('active', true); 
if (searchTerm) {
grUser.addQuery('name', 'CONTAINS', searchTerm); 
}
grUser.query();

while (grUser.next()) {

uniqueUsers.add(grUser.sys_id.toString());
}

  • if (uniqueUsers.size > 0) {
    answer = 'sys_idIN' + Array.from(uniqueUsers).join(',');
    } else {
    answer = 'sys_idIN';
    }
6 REPLIES 6

Yes, that's to be expected.  You're querying the sys_user_grmember table, which will naturally have a TON of entries for users who are in multiple groups.  
What you've done is made sure the array forming your IN has unique values but that doesn't stop it from returning multiple results from the sys_user_grmember table.

Essentially:  "Get me memberships where user is BOB or DOUGLAS"
"OK....
BOB (helpdesk)
BOB (helpdesk 2)
DOUGLAS (dance instructor team)
DOUGLAS (dancers who do the dougie team)
DOUGLAS (dancers who do ballet team)

 

As @Brad Bowman  stated, this reference really should be to sys_user.  You want a USER to point at.  You do not want a USER MEMBER to point at.

Runjay Patel
Giga Sage

Hi @Mani60 ,

 

Not sure what's your business logic to reference this field to group member table but generally it should point to user table. and then you can put the reference qualifier based on your conditions like user should only show based on assigned group.

If you can tell me business logic then i can guide you best solution.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------