Error: Script can't find value within an array

Topic Labels: Automations
110 1
Showing results for 
Search instead for 
Did you mean: 
4 - Data Explorer
4 - Data Explorer

I'm trying to run a script with 4 inputs, one is a Users name and the other three are lists of users labeled Junior, Mid, Senior. I want to return Junior, Mid or Senior depending on which list the User is in, the user will always be in one of the lists. When I run tests where I search for a user within the Junior list the output is 'Name not found in any list'.

I will attach my script code below; the logic seems right however it does not find the user in the lists.


function findUserList(User, SeniorList, MidList, JuniorList) {
// Check if the inputs are strings and split them into arrays; if not, use them as they are
let seniorArray = Array.isArray(SeniorList) ? SeniorList : SeniorList.toString().split(", ");
let midArray = Array.isArray(MidList) ? MidList : MidList.toString().split(", ");
let juniorArray = Array.isArray(JuniorList) ? JuniorList : JuniorList.toString().split(", ");

// Iterate through each list to find the User
if (seniorArray.includes(User)) {
return 'Senior';
} else if (midArray.includes(User)) {
return 'Mid';
} else if (juniorArray.includes(User)) {
return 'Junior';
} else {
return 'Name not found in any list';
let inputVar = input.config();
let user = inputVar.User;
let seniorlist = inputVar.SeniorList;
let midList = inputVar.MidList;
let juniorList = inputVar.JuniorList;

let listName = findUserList(user, seniorlist, midList, juniorList);

1 Reply 1

If you could provide a read only link to an example base with the automation setup I could help you take a look at it!  Somewhat difficult troubleshooting code over the forums like this