Identifying where a group is being used in a Flow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 07:56 AM
Hi all,
We need to find all flows, catalog items, and knowledge bases that are using a specific group. It’s something the client requested so they can understand the impact of changing that group.
We tried running a query for the flows, but it’s not optimized — each one takes about 8 minutes to run.
Any ideas on how we could make this faster?
Thanks in advance!
- /*******************************QUERY*********************************/
// Sys_id del grupo
var targetSysId = 'XXXXXXXXXXX';
// Consulta todos los flows activos en la tabla sys_flow
var grFlow = new GlideRecord('sys_hub_flow');
grFlow.addQuery('active', true);
//grFlow.addQuery('type', "Flow");
grFlow.query();
while (grFlow.next()) {
var flowSysId = grFlow.getUniqueValue();
var flowName = grFlow.name.toString();
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint('https://XXXXXXXX.service-now.com/api/now/processflow/flow/' + flowSysId + '?sysparm_transaction_scope=global');
request.setBasicAuth('userXXX', 'PpassXXXXX@');
var response = request.execute();
var body = response.getBody();
if (body.indexOf(targetSysId) !== -1) {
gs.info(' El grupo ESTÁ referenciado en el flow: ' + flowName + ' (' + flowSysId + ')');
}
}
- /******************************************** RESPONSE **********************************************/
*** Script: El grupo ESTÁ referenciado en el flow: Axs: Access management (09d5db801bb041d09352db51f54bcbf2)
*** Script: El grupo ESTÁ referenciado en el flow: ZZZ: Generic Request Flow (34ee25561b15d850245165b33a4bcb53)
*** Script: El grupo ESTÁ referenciado en el flow: QWQ: Ariba is selected (5079651947f62a90441fa769116d4342)
*** Script: El grupo ESTÁ referenciado en el flow: Access to Applications (53301a07339e16d060c34d919e5c7b5b)
*** Script: El grupo ESTÁ referenciado en el flow: ASD: Validity Extension (c18967801b3441d09352db51f54bcb42)
*** Script: El grupo ESTÁ referenciado en el flow: ASD: Access SAP (d15030e133521ad0c9ee76273e5c7b86)
*** Script: El grupo ESTÁ referenciado en el flow: QWE: RPA compact (fd6272a71bdb8d1013ab53dc4b4bcb5c)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 07:59 AM
did you try to run that in chunk with setLimit(10) or setLimit(40)?
Create multiple fix scripts (4-5) and run them in parallel.
It's bound to take time as it searches complete flow in detail
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2025 09:53 AM
I am testing something like that:
var targetSysId = 'XXXXXXX';
var chunkSize = 100;
var startIndex = 0; // Cambiá este valor a 0, 40, 80, etc. para cada chunk
var endIndex = startIndex + chunkSize;
var grFlow = new GlideRecord('sys_hub_flow');
grFlow.addQuery('active', true);
grFlow.orderBy('sys_created_on');
grFlow.query();
var currentIndex = 0;
while (grFlow.next()) {
if (currentIndex >= startIndex && currentIndex < endIndex) {
var flowSysId = grFlow.getUniqueValue();
var flowName = grFlow.name.toString();
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('get');
request.setEndpoint(gs.getProperty('glide.servlet.uri') + 'api/now/processflow/flow/' + flowSysId + '?sysparm_transaction_scope=global');
request.setBasicAuth('userXXXX', 'PpassXXXX@');
var response = request.execute();
var body = response.getBody();
if (body.indexOf(targetSysId) !== -1) {
gs.info(' El grupo está en el flow: ' + flowName + ' (' + flowSysId + ')');
}
}
currentIndex++;
// Salir si ya pasamos el límite
if (currentIndex >= endIndex) break;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Did you get this to work?
Thanks,
Chad