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.

How to get access catalog items for end users through user criteria ?

karishma shaik
Tera Contributor

Hi All,

 

I have Requirement ,How to find out the access of catalog items for end users through user criteria through background script

 

for example: 

first I find out the what group have in that catalog item in user criteria, then next I find out Who have the users in that group then next I will print that catalog item .

 

Please help me on this 

 

4 REPLIES 4

Bert_c1
Kilo Patron

Hi,

 

Here's a start:

 

var uc = new GlideRecord('user_criteria');
uc.addEncodedQuery('group!=NULL');
uc.query();
gs.info("Found " + uc.getRowCount() + " user_criteria records where group is not null.");
while (uc.next()) {
    gs.info("Name: " + uc.name + " has groups: " + uc.group);
    var grpMembers = new GlideRecord('sys_user_grmember');
    var grpMemberQuery = 'groupIN' + uc.group;
    grpMembers.addEncodedQuery(grpMemberQuery);
    grpMembers.query();
    while (grpMembers.next()) {
        gs.info("Group: " + grpMembers.group.getDisplayValue() + " has user: " + grpMembers.user.getDisplayValue());
    }
}

I don't know how records in the user_criteria table relate to catalog items. Others here may help on that. But the above shows which users belong to groups that are specified on user_criteria records.

Hi ,

 

Thank you very for given this replay , It's working Fine . But How to find out the which catalog Item and Category have which user belong group .

 

Please help me on this

Hi, the sc_cat_item table has a reference field to the sys_user_group table. Use similar logic to what I posted for the 'user_criteria' table.

 

The sc_cat_item table also has reference field ('category') to the sc_category table. So logic can be added to query the sc_category table associated to the sc_cat_item table record, and see info from that record.

hi,

Maybe the following script is what you are looking for catalog item group members:

 

 

 

 

// Get group members for sc_cat_item records that have a value for 'group'
var sci = new GlideRecord('sc_cat_item');
sci.addEncodedQuery('group!=NULL');
sci.query();
gs.info("Found " + sci.getRowCount() + " sc_cat_item records where group is not null.");
while (sci.next()) {
    gs.info("Name: " + sci.name + " has groups: " + sci.group);
    var grpMembers = new GlideRecord('sys_user_grmember');
    var grpMemberQuery = 'groupIN' + sci.group;
    grpMembers.addEncodedQuery(grpMemberQuery);
    grpMembers.query();
    while (grpMembers.next()) {
        gs.info("Group: " + grpMembers.group.getDisplayValue() + " has user: " + grpMembers.user.getDisplayValue());
    }
}

 

 

 

and for user/groups related to Category, I don't have anything useful. sc_cat_item has a reference field to sc_category. the sc_cat_item table has a reference field to sys_user_group with label "Fulfillment group". The above script has that logic.

 

Also, see:

https://www.servicenow.com/community/developer-articles/should-servicenow-admins-learn-javascript-an...

 

and:

https://developer.servicenow.com/dev.do#!/learn/courses/utah#scripting-in-servicenow