- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Community,
I need help identifying the list of Service Catalog items that are associated with the following approver groups:
FSD-FCIT_SM-APR
FSD-FCIT_SO-APR
This is an information-only requirement. I am not looking to modify any workflows or approvals, just to understand where these groups are currently used as approvers (via catalog item approvals, workflows, flows, or approval rules).
Could you please suggest the best approach or tables to check to extract this information accurately?
If possible please provide Screenshots for better understanding .
Thanks in advance for your guidance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Background script like this, please enhance
var groups = ['CAB Approval'];
var catItems = {};
var groupGr = new GlideRecord('sysapproval_group');
groupGr.addQuery('assignment_group.name', 'IN', groups.join(','));
groupGr.query();
while (groupGr.next()) {
var ritmSysId = groupGr.getValue('parent'); // sys_id of sc_req_item
if (!ritmSysId) continue;
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get(ritmSysId)) {
var catItemSysId = ritmGr.getValue('cat_item');
if (catItemSysId) {
catItems[catItemSysId] = ritmGr.cat_item.name.toString() || catItemSysId;
}
}
}
// Output unique catalog items
gs.info('Catalog Items with group approvals:');
for (var sysId in catItems) {
gs.info('Sys ID: ' + sysId + ', Name: ' + catItems[sysId]);
}
gs.info('Total: ' + Object.keys(catItems).length);
Output: it gave me 2 catalog items which are using CAB Approval as approval group
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Background script like this, please enhance
var groups = ['CAB Approval'];
var catItems = {};
var groupGr = new GlideRecord('sysapproval_group');
groupGr.addQuery('assignment_group.name', 'IN', groups.join(','));
groupGr.query();
while (groupGr.next()) {
var ritmSysId = groupGr.getValue('parent'); // sys_id of sc_req_item
if (!ritmSysId) continue;
var ritmGr = new GlideRecord('sc_req_item');
if (ritmGr.get(ritmSysId)) {
var catItemSysId = ritmGr.getValue('cat_item');
if (catItemSysId) {
catItems[catItemSysId] = ritmGr.cat_item.name.toString() || catItemSysId;
}
}
}
// Output unique catalog items
gs.info('Catalog Items with group approvals:');
for (var sysId in catItems) {
gs.info('Sys ID: ' + sysId + ', Name: ' + catItems[sysId]);
}
gs.info('Total: ' + Object.keys(catItems).length);
Output: it gave me 2 catalog items which are using CAB Approval as approval group
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @nameisnani ,
Please once check below code :
var flowsWithGroupApprovals = [];
// Step 1: Get all flows with group approvals
var gr = new GlideRecord('sys_hub_flow');
gr.query();
while (gr.next()) {
var labelCache = gr.getValue('label_cache');
if (labelCache && labelCache.indexOf('sys_user_group') > -1 &&
labelCache.indexOf('approval_conditions') > -1) {
try {
var labelCacheObj = JSON.parse(labelCache);
var groupSysId = '';
var groupLabel = '';
for (var i = 0; i < labelCacheObj.length; i++) {
var item = labelCacheObj[i];
if (item.reference == 'sys_user_group') {
groupSysId = item.name.replace(/{{static\.|}}'/g, '');
groupLabel = item.label;
}
}
if (groupSysId) {
flowsWithGroupApprovals.push({
flowId: gr.sys_id.toString(),
flowName: gr.name.toString(),
groupId: groupSysId,
groupLabel: groupLabel
});
}
} catch (e) {}
}
}
// Step 2: For each flow, check if it has catalog items linked
var groupsWithCatalogItems = {};
for (var j = 0; j < flowsWithGroupApprovals.length; j++) {
var flow = flowsWithGroupApprovals[j];
// Find catalog items directly linked to this flow
var catGr = new GlideRecord('sc_cat_item');
catGr.addQuery('flow_designer_flow', flow.flowId);
catGr.query();
// Only process if catalog items exist
if (catGr.hasNext()) {
// Initialize group entry if not exists
if (!groupsWithCatalogItems[flow.groupId]) {
// Get group name
var grpRec = new GlideRecord('sys_user_group');
var groupName = '';
if (grpRec.get(flow.groupId)) {
groupName = grpRec.name.toString();
}
groupsWithCatalogItems[flow.groupId] = {
groupId: flow.groupId,
groupName: groupName,
groupLabel: flow.groupLabel,
flows: [],
catalogItems: []
};
}
// Add flow info
groupsWithCatalogItems[flow.groupId].flows.push({
name: flow.flowName,
id: flow.flowId
});
// Add catalog items
while (catGr.next()) {
groupsWithCatalogItems[flow.groupId].catalogItems.push({
name: catGr.name.toString(),
number: catGr.number.toString(),
sysId: catGr.sys_id.toString()
});
}
}
}
// Step 3: Display results - ONLY groups with catalog items
gs.print('========================================');
gs.print('GROUPS WITH CATALOG ITEM APPROVALS');
gs.print('========================================');
var groupCount = 0;
for (var groupId in groupsWithCatalogItems) {
var group = groupsWithCatalogItems[groupId];
groupCount++;
gs.print('\n[' + groupCount + '] Group: ' + group.groupName);
gs.print(' Group Sys_ID: ' + group.groupId);
gs.print(' Group Label: ' + group.groupLabel);
gs.print(' Associated Flows:');
for (var f = 0; f < group.flows.length; f++) {
gs.print(' - ' + group.flows[f].name);
}
gs.print(' Catalog Items:');
for (var c = 0; c < group.catalogItems.length; c++) {
gs.print(' - ' + group.catalogItems[c].name +
' (' + group.catalogItems[c].number + ')');
}
gs.print(' ---');
}
gs.print('\n========================================');
gs.print('Total groups with catalog items: ' + groupCount);
gs.print('========================================');
This code will extract all groups which are linked with any catalog items.
If this helps you then mark it as helpful and accept as solution.
Regards,
Aditya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I need only for this two approvral groups
FSD-FCIT_SM-APR
FSD-FCIT_SO-APR
whihch are catalog items are assoicated with this - could you pplease help me here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @nameisnani ,
Have you checked this by running the above code in your Background Script to confirm whether the required group names are being returned or not?
I also tried a similar approach as suggested by Ankur. However, that method only returns records where approvals have already been generated.
If an approval group is configured but has not yet received any approval request, it becomes difficult to identify whether that group is actually linked or not using runtime approval tables.
This is why checking configuration-level data (such as approval rules, workflows, or catalog item approval settings) is more reliable than relying only on approval records.
Once run above code in your background script and check which group names are getting there .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Nameisnani,
This is what we do in our project to check the group association with Workflow of the catalogs.
1. Run this fix script ( per group ,it will show result)
Sample Code:
checkAssociatedWF('<sys_id of FSD-FCIT_SM-APR>', 'FSD-FCIT_SM-APR');
function checkAssociatedWF(groupSysId, groupName) {
var wfCOunt = 0;
var activity = new GlideRecord('wf_activity');
activity.addQuery('workflow_version.published', '=', true);
activity.query();
var activityArray = [];
while(activity.next()){
activityArray.push(activity.getUniqueValue());
}
var workflow = new GlideRecord('sys_variable_value');
var workflowQuery = workflow.addQuery('value', 'CONTAINS', groupSysId);
workflowQuery.addOrCondition('value', 'CONTAINS', groupName);
workflow.addQuery('document_key','IN',activityArray);
workflow.query();
var workflowArray = [];
var workflowName = '';
while(workflow.next()){
workflowName = workflow.document_key.workflow_version.getDisplayValue('name');
if(workflowArray.indexOf(workflowName) < 0){
if(workflowArray.length < 10){
workflowArray.push(workflowName);
}
else if(workflowArray.length == 10){
workflowArray.push('more...');
break;
}
}
}
gs.print('*** WF associated records:\n' + workflowArray.toString());
}
2. Open shortlisted workflow in workflow editor. check whether mentioned group is Approval group or fulfillment group.
3. You will get your answer for approval group.
