Encountered undeclared output variable error in Script action - Flow designer

Mahalakshmi Rav
Tera Contributor

I'm working on a Flow Designer Action where I need to filter users based on the itil role using a Script Include and return a list of their sys_ids via Script step output variable.

 

Script Include (GetITILValidators):

 

var GetITILValidators = Class.create();
GetITILValidators.prototype = {
initialize: function() {},

getITILUsers: function(validatorsList) {
var itilUsers = [];

if (!validatorsList)
return itilUsers;

var userIds = validatorsList.split(',');

for (var i = 0; i < userIds.length; i++) {
var user = new GlideRecord('sys_user');
if (user.get(userIds[i]) && user.roles.toString().includes('itil')) {
itilUsers.push(user.sys_id.toString());
}
}

return itilUsers;
},

type: 'GetITILValidators'
};

 

Flow Designer Action:
Input: user_ids (Type: String, Mandatory)

MahalakshmiRav_0-1754342263443.png

 

Output: filtered_users (Type: Array.String)

MahalakshmiRav_1-1754342278563.png

Script Step:

(function execute(inputs, outputs) {
    var helper = new GetITILValidators();
    var result = helper.getITILUsers(inputs.user_ids);
    outputs.filtered_users = result;
})(inputs, outputs);
 
MahalakshmiRav_2-1754342351016.png
Whenever I run a Test in the Action Designer using any valid user sys_id (with itil role) the test fails with this error
Warning: Encountered undeclared output variable: filtered_users

 

MahalakshmiRav_3-1754342462748.png

What adjustment do I need to make in the code or Flow Action setup to fix this?

Any help would be appreciated!

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Mahalakshmi Rav 

did you create an input and output variable under the Script Step?

You need to create it with the correct type based on what script include returns and based on what the action is accepting as input.

Then map the Action Output with Script Step Output

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

9 REPLIES 9

@Ankur Bawiskar Thank you for your response, it's already declared in the Script action as an array.string

 

MahalakshmiRav_1-1754574212045.png

 

@Mahalakshmi Rav 

Click on Exit Edit mode and did you map the output of action with Script Step output?

AnkurBawiskar_0-1754575345930.png

 

 

Like this I mapped

AnkurBawiskar_1-1754575566111.png

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

This worked, Now i can see the filtered users output in the test script action results.

MahalakshmiRav_0-1754576512131.png

Unfortunately when i ran a test with the main flow, this is returning empty value.

MahalakshmiRav_3-1754576622514.png

 


MahalakshmiRav_2-1754576597091.png

 

@Mahalakshmi Rav 

are you not able to iterate that output using For Each?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Yes, it's because filtered_users output was returning an empty array and the for each step didn't iterate over any items