Create catalog task if list collector is empty

alexm3
Kilo Expert

Hello,

I have a list collector variable on a catalog form. In the workflow, i'm trying to create an IF script to check if the list collector  values are empty or not. If the values are empty the workflow should not create a task. If any value is selected then the workflow should create a task.

I am currently using the script below:

//variable name = non_standard

 

answer = ifScript();
function ifScript() {
var nonstandardList = current.variables.non_standard.toString(); 
var arrayList = nonstandardList.split(",");
if (arrayList.length > 0) {
return 'yes';
} else {
return 'no';

}

}

Unfortunately this is not working, the workflow will read the script as true regardless of what values are present in the list collector,  empty or not. 

The variable looks like this:

 

find_real_file.png

if any values from the left are selected on right the workflow should create the task, if left empty the workflow should not create the task.

Any ideas would be greatly appreciated.

Thanks,

Alex 

 

1 ACCEPTED SOLUTION

alexm3
Kilo Expert

Hey,

 

After doing this post,  I tried one more method that actually worked and it looks like this:

answer = ifScript();

function ifScript() {


var list = current.variables.non_standard.toString();

var arrayList = list.split(",");

if(arrayList != ''){

return 'yes';


} else {


return 'no';


}


}

 

Thank you for your suggestion, hopefully both these scripts will help other people like me. 🙂

Alex

View solution in original post

2 REPLIES 2

Anurag Tripathi
Mega Patron
Mega Patron

Hi Alex,

 

Try this

 

answer = ifScript();
function ifScript() {
if (JSUtil.notNil(current.variables.non_standard)) {
return 'yes';
} else {
return 'no';

}

}

-Anurag

alexm3
Kilo Expert

Hey,

 

After doing this post,  I tried one more method that actually worked and it looks like this:

answer = ifScript();

function ifScript() {


var list = current.variables.non_standard.toString();

var arrayList = list.split(",");

if(arrayList != ''){

return 'yes';


} else {


return 'no';


}


}

 

Thank you for your suggestion, hopefully both these scripts will help other people like me. 🙂

Alex