- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2025 05:54 AM
I have a requirement to create a Change Task only if the validators(list var from change request) have the ITIL role and it should be automatically assigned to them.
What I tried:
I used a Script Include to check whether users have the ITIL role.
I called this Script Include inside a Script Action.
Based on the Script Action’s output variable, the Main Flow is supposed to create a Change Task and assign it to the filtered users.
My Script include:
My Script action:
I ran a test for the script action by giving the user_ids (i.e) one user id is ITIL and other is Non-ITIL
It's giving the right output values.
Main flow:
When I ran a test for this main flow, the "Create Task" step didn’t get triggered. This is because the output variable is empty and it’s not passing the ITIL users. I created the change request in the backend and provided the same validators that I used in the Script Action test.
Can you please tell me what went wrong here?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2025 06:12 AM
when you call from main flow it's not treating the input correctly
Do this
1) make input user_ids as Array.String instead of String
2) then use this in script step i.e. convert array to string value and then pass to script include function
3) Update script include as this -> no need to split, directly use the value coming to function
var GetITILValidators = Class.create();
GetITILValidators.prototype = {
initialize: function() {},
getITILUsers: function(userIds) {
var filtered = [];
if (!userIds) {
return filtered;
}
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', 'IN', userIds);
userGR.query();
while (userGR.next()) {
var hasRole = new GlideRecord('sys_user_has_role');
hasRole.addQuery('user', userGR.sys_id);
hasRole.addQuery('role.name', 'itil');
hasRole.query();
if (hasRole.hasNext()) {
filtered.push(userGR.sys_id.toString());
}
}
return filtered;
},
type: 'GetITILValidators'
};
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-21-2025 07:11 AM
you didn't update the script include correctly.
Line 21 should use userIds and not ids
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-21-2025 10:45 AM
Thank you @Ankur Bawiskar , the solution worked but I’m facing two issues
Out of the 2 ITIL users, only one task is getting created. Ideally 2 tasks should be created based on the ITIL Validators count and each task should be assigned to the respective filtered user. For eg, if there are 3 ITIL users (in the validators field) in the change request, then 3 ctasks should be created and assigned to each filtered users
- I’m trying to set the Change Task assignee based on the filtered users, but the filtered users field is greyed out in the main Flow, so I’m unable to map the value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2025 08:05 PM
Glad to know that my solution worked.
Would you mind marking my response as correct as I provided solution to your original question?
The discussion can continue on answered thread as well.
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-21-2025 08:14 PM
see this where I shared solution on how to get and iterate. I used JSON structure and you can use the same
Also attaching the gif here
also check below link on how to do it in another way
How to iterate an Array.String in the flow designer? -> response from Hitoshi
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-22-2025 01:49 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader