How to get access catalog items for end users through user criteria ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 11:12 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-21-2023 02:06 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 12:26 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 07:28 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2023 09:42 AM - edited 03-22-2023 01:47 PM
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:
and:
https://developer.servicenow.com/dev.do#!/learn/courses/utah#scripting-in-servicenow