The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Populate List Collector Variable from String Array (Service Portal)

JJG
Kilo Guru

I have a string array that I would like to pass to a list collector variable. Unfortunately it is only setting the last object in the array. How can I make it populate the entire array?

 

 

Script: 

var seperate = answer.split(',');  // "answer" is a comma seperated string



for (var i = 0; i < seperate.length; i++) {


g_form.setValue("test_list_collector_variable", seperate[i]);


}

 

1 ACCEPTED SOLUTION

Hi,

What does "it didn't work" mean...because in this scenario, it wouldn't be the same reason that you've mentioned above.

I have no idea what your "answer" actually is...so please verify that.

Then...if it's a array of separated values, as you've mentioned, using:

seperate.join(',')

does in fact work, otherwise, if it's string from a script include that you're getting, for example, you can use:

g_form.setValue('field_name', answer.toString());

Again, as long as it's a comma separated list of sys_ids relevant to that field (reference is the right table and the values are sys_ids).

Please mark reply as Helpful/Correct, if applicable. Thanks!

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

13 REPLIES 13

Hi,

Thanks.

Yeah, I know what I mentioned above does work because I too made sure and just worked with someone else the other day around this whole thing.

It's most likely an error on the script side that is beyond what I've mentioned.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

This is a client script so your server side script will not work. It is also on a Service Portal form.

Hi JJG,

I had tried this using JavaScript executer on the incident form and it works with the same logic in the client side as well. Refer below screenshot

find_real_file.png

Could you share some screenshot on what exactly you are trying to achieve and what output is being received.

Regards,

Deepankar Mathur 

dmathur09
Kilo Sage
Kilo Sage

Hi JJG,

Kindly use seperate [i].join(',') at the end.

Regards,

Deepankar Mathur