- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 06:51 AM
I am trying to use an ifscript to check if a list collector selected values is empty or not. If it's not empty, I will generate tasks based on the selection.
Right now my script looks like this but I see a warning:
Solved! Go to Solution.
- Labels:
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 07:13 AM
Try this (typo also corrected on line 2)
answer = ifScript();
function ifScript() {
var accessoriesList = current.variables.accessories.toString(); //convert the variable list to string
var arrayList = accessoriesList.split(",");
if (arrayList.length > 0) {
return 'yes';
} else {
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 06:54 AM
Hi Ravikant,
Please give your script here...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 06:59 AM
In lieu of an if script, here is what I suggest:
answer = ifScript();
function ifScript() {
var val = current.getValue('watch_list');
// Check if it is empty
if (val.nil()) {
return "Yes";
} else {
return "No";
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-28-2017 07:16 AM
Hi Ravikant,
Use an if condition in the workflow and assuming that your workflow is on RITM table here is the script you can use:
use your variable name in the variableName highlighted in bold.
answer = ifScript();
function ifScript() {
var val = current.variables.<variableName>;
if (JSUtil.nil(val)) {
return "Yes"; // is empty
} else {
return "No"; // not empty
}
}
The transition from "No" you can take to Task generation since list collector is not empty
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader