How to create tasks based on value selection in list collector

Rhonda9
Tera Expert

Hello,

 

I have been trying to configure a workflow to auto generate tasks based on list collector value selected.   It is creating the task based on the 1st value selected, the other tasks will not generate.

I created an If Activity script in the workflow, but still only 1 task.  Please provide me some guidance... Thank you

 

An if Activity Script is created for each variable value: 

below is a script for one of the values:

answer = ifScript();

function ifScript() {
var arrayUtil = new ArrayUtil();
var list = current.variables.vm_select_a_service.getDisplayValue();
var arrayList = list.split(",");
if (arrayUtil.contains(arrayList, "Assign Voicemail")) {
return 'yes';
}
return 'no';
}

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Rhonda9 

It's because when you obtain the display value at the line below, it produces a string separated by commas with spaces at the beginning of each element.

 

var list = current.variables.vm_select_a_service.getDisplayValue();

 

Example:

 

element0, Assign Voicemail, element2, etc

 

Consequently, the arrayUtil.contains in your if condition returns false as the text "Assign Voicemail" lacks the initial space.

 

For resolution, you can leverage indexOf for your if condition. like below

 

answer = ifScript();

function ifScript() {
    var list = current.variables.vm_select_a_service.getDisplayValue();
    if (list.indexOf("Assign Voicemail") >= 0) {
        return 'yes';
    }
    return 'no';
}

 

 

Cheers,

Tai Vu

View solution in original post

4 REPLIES 4

Anil Lande
Kilo Patron

Hi @Rhonda9 

Can you please provide how your workflow is configured? what all activities used to create tasks (how many if activities?)

Which script is not working?

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

You can try below:

answer = ifScript();

function ifScript() {
var arrayUtil = new ArrayUtil();
var list = current.variables.vm_select_a_service.getDisplayValue();
var arrayList = list.split(",");
if (arrayList.indexOf("Assign Voicemail")>-1) {
return 'yes';
}
return 'no';
}
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Tai Vu
Kilo Patron
Kilo Patron

Hi @Rhonda9 

It's because when you obtain the display value at the line below, it produces a string separated by commas with spaces at the beginning of each element.

 

var list = current.variables.vm_select_a_service.getDisplayValue();

 

Example:

 

element0, Assign Voicemail, element2, etc

 

Consequently, the arrayUtil.contains in your if condition returns false as the text "Assign Voicemail" lacks the initial space.

 

For resolution, you can leverage indexOf for your if condition. like below

 

answer = ifScript();

function ifScript() {
    var list = current.variables.vm_select_a_service.getDisplayValue();
    if (list.indexOf("Assign Voicemail") >= 0) {
        return 'yes';
    }
    return 'no';
}

 

 

Cheers,

Tai Vu

@Tai Vu Thank you so much, it works!