- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 07:29 AM
I'm struggling with some script in a Flow. I'm using the Set Flow Variables Flow Logic. If I utilize the first part of the script and simply return deptID, I get "ITO" as expected. However, when I try to verify that the deptID that comes in from the Catalog Variables is one of the options listed in the deptList array, it returns "false" every time. What am I missing?
var deptList = ["CLM", "CRQ", "CRS", "CRU", "ITD", "ITO", "ITS", "OPF"];
var deptID = fd_data.trigger.request_item.variables.dept;
var containsDept = false;
for (var i = 0; i < deptList.length; i++) {
if (deptID.includes(deptList[i])) {
containsDept = true;
break;
}
}
return containsDept;
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 07:39 AM
@darronf Try converting the dept variable to string (if it is not a reference variable )and see if the match works
var deptList = ["CLM", "CRQ", "CRS", "CRU", "ITD", "ITO", "ITS", "OPF"];
var deptID = fd_data.trigger.request_item.variables.dept.toString();
var containsDept = false;
for (var i = 0; i < deptList.length; i++) {
if (deptID.includes(deptList[i])) {
containsDept = true;
break;
}
}
return containsDept;
If dept is a reference variable then you should try the following.
var deptList = ["CLM", "CRQ", "CRS", "CRU", "ITD", "ITO", "ITS", "OPF"];
var deptID = fd_data.trigger.request_item.variables.dept.name.toString(); //if dept is a reference variable
var containsDept = false;
for (var i = 0; i < deptList.length; i++) {
if (deptID.includes(deptList[i])) {
containsDept = true;
break;
}
}
return containsDept;
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 07:35 AM
Hi @darronf ,
You must be getting the sys_id of the department from your variable if it is a reference variable. If that is the case, you have to do :
var deptID = fd_data.trigger.request_item.variables.dept.name;
If my response helped you, please click on "Accept as solution" and mark it as helpful.
- Saloni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 08:15 AM
Thanks for your reply. I was needing to convert the variable to a string. Appreciate your help!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 07:39 AM
@darronf Try converting the dept variable to string (if it is not a reference variable )and see if the match works
var deptList = ["CLM", "CRQ", "CRS", "CRU", "ITD", "ITO", "ITS", "OPF"];
var deptID = fd_data.trigger.request_item.variables.dept.toString();
var containsDept = false;
for (var i = 0; i < deptList.length; i++) {
if (deptID.includes(deptList[i])) {
containsDept = true;
break;
}
}
return containsDept;
If dept is a reference variable then you should try the following.
var deptList = ["CLM", "CRQ", "CRS", "CRU", "ITD", "ITO", "ITS", "OPF"];
var deptID = fd_data.trigger.request_item.variables.dept.name.toString(); //if dept is a reference variable
var containsDept = false;
for (var i = 0; i < deptList.length; i++) {
if (deptID.includes(deptList[i])) {
containsDept = true;
break;
}
}
return containsDept;
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 08:16 AM
Thanks so much for your help! toString() did the trick.