- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
3 weeks ago
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
3 weeks ago
Hey,
i think this is due to your input type of the action. Just to confirm, could you - in your main flow - instead of using a data pill to assign the input value, use a script for the value retrival? So instead of providing a data-pill for the "user_ids" instead add a script (with the button right next to it). In that script, just add a .getValue('whatever_the_field_name_of_the_validators_is');
Your input variable configuration of your action is a string. However, the field you are using in the data pill seems to be an array. When using data-pills, field types are kept and not converted to simple types. This could be the issue here.
Hope this helps,
Regards
Fabian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Thanks @Fabian Kunzke , I tried using the script option with current.getValue('u_validators'); in my main flow, but it’s throwing an error:
{ "Action Status": { "code": 1, "message": "Error: Cannot convert null to an object.,Detail: Cannot convert null to an object." } }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
3 weeks ago
Hi @Ankur Bawiskar ,
Thanks for your response, I tried as per your suggestion but it's throwing the "Error: "ids" is not defined.,Detail: "ids" is not defined. error.