background script to identify particular assignment group in all workflows and flow designers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 11:07 AM
Hi
I need to identify the workflows and flow designers that are using particular assignment group- through background script. If anybody has the script kindly help here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2024 09:03 PM
Hello @sinu2
To identify Workflows and Flow Designers that are using a particular Assignment Group in ServiceNow, you typically need to search through the Flow Designer’s Action and Workflow’s Activity configurations. This requires a bit of scripting.
Workflows are a bit more static, and their details are stored in a way that you can query directly. Assume we are searching for an Assignment Group with a sys_id ‘assignment_group_sys_id_here’.
// Define the sys_id of your target Assignment Group
var targetAssignmentGroupSysId = '0a52d3dcd7011200f2d224837e6103f2';
// Query the wf_activity table for any ‘Assign to’ type of activities that might reference the Assignment Group
var activityQuery = new GlideRecord('wf_activity');
activityQuery.addQuery('activity_definition', 'CONTAINS', targetAssignmentGroupSysId); // You may need to adjust this based on actual data and activity type
activityQuery.query();
while (activityQuery.next()) {
gs.info('Workflow Activity Found: ' + activityQuery.getValue('name') + ' in Workflow: ' + activityQuery.getValue('workflow_version'));
}
For Flow Designer
For the Flow Designer, since flows are stored in a more structured and possibly encrypted format depending on the ServiceNow version, direct querying might not give the precise results, especially for complex flows. You will probably need to fetch and iterate over flow actions to evaluate their definitions.
A rough outline would be:
1. Query all flows (sys_flow) to fetch each flow.
2. For each flow, fetch associated actions (flow_designer_action).
3. Check each action’s inputs or definitions for the Assignment Group’s sys_id.
Since ServiceNow doesn’t directly expose all internal representations of flows and their configurations via simple database queries, and considering the possibility of ongoing enhancements and changes in how flows are defined, it’s crucial to refer to the latest ServiceNow documentation for a more tailored solution.
Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help us a lot.
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 08:30 AM - edited 03-25-2024 08:31 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-25-2024 08:20 PM
Hi @sinu2
Note: Please Mark my response Accepted and Helpful If this Helps you to understand. This will help both the community and me.
- Keep Learning
Thanks & Regards
Deepak Sharma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2024 02:37 AM
NOt working Mand also kindly see the below extension code any suggestions?
[Saturday 00:33] Rajesh R
var targetAssignmentGroupSysId = '346ca3221ba55d1008b8ea0dad4bcbda';
var arr = [];
// Query the wf_activity table for any ‘Assign to’ type of activities that might reference the Assignment Group
var activityQuery = new GlideRecord('wf_activity');
//activityQuery.addQuery('activity_definition', 'CONTAINS', targetAssignmentGroupSysId); // You may need to adjust this based on actual data and activity type
activityQuery.addEncodedQuery('activity_definition=38891b6f0a0a0b1e00efdfdd77602027^sys_id=1c76db2f1ba10d108caa64e1604bcbcf');
activityQuery.query();
while (activityQuery.next()) {
//gs.print('Workflow Activity Found: ' + activityQuery.getValue('name') + ' in Workflow: ' + activityQuery.getValue('workflow_version'));
//gs.info(activityQuery.vars.task_fulfillment_group.getDisplayValue());
if (activityQuery.vars.task_fulfillment_group = '346ca3221ba55d1008b8ea0dad4bcbda') {
gs.info(activityQuery.vars.task_fulfillment_group);
}
gs.info(activityQuery.vars);
// arr.push(activityQuery.vars.task_fulfillment_group);
}
//gs.info(arr);