Requested Item reference field - Exact filters not working

Ballela Siva Te
Tera Contributor

Hi Team,

 

I am working on a catalog item, one field is a reference field where users from a specific group should populate.

BallelaSivaTe_0-1720612489595.png

But I have to use reference table as sys_user table as that tableis accessible to end users.

 

I have to write a script include and call it over catalog item

below is the script :

var getgrmember = Class.create();
getgrmember.prototype = {
    initialize: function() {
    },

    getUsersInGroup: function() {
       var grMember = new GlideRecord('sys_user_grmember');
       grMember.addQuery('group', 'c5e4ae74975e9110902978ae2153afa3');
    gs.log("getgrmember-script include has run");
       grMember.query();
       var userIDs = [];
       while (grMember.next()) {
           userIDs.push(grMember.user.toString());
       }
       return 'sys_idIN' + userIDs.join(',');
   },

    type: 'getgrmember'
};
 
Below is how I called the script include
javascript : new getgrmember().getUsersInGroup();
 
I am getting the whole user table when I click on the name of the service manager dropdown. please correct me
 
Regards,
B Siva Teja

 

 

 

1 REPLY 1

johnfeist
Mega Sage
Mega Sage

Hi Ballela,

I can suggest a few things:

Best practice is to never embed sys_ids in a script.  You are better off looking up the group by name and then getting the sys_id.

Add a statement like this right after grMember.query()

var grMemberCount = grMember.getRowCount(); 
gs.log("grMemberCount " + grMemberCount);

 

That will tell you if your filter is working correctly.  You can also check the number of entries being returned by adding a log statement to give you the length of userIDs.

 

I've seen some number of cases where ServiceNow ends up changing javascript: into javascript &colon.  That can also be the culprit if the correct number of entries is being returned.

Hope that helps.

:{)

Helpful and Correct tags are appreciated and help others to find information faster