The CreatorCon Call for Content is officially open! Get started here.

Setting List Collector Selections in a Script

Mike McCall
Giga Guru

I've seen a lot about how to default the filter for a list collector (pre-filling the "left side"), but I can't seem to find anything about defaulting the selected values of a list collector (to pre-fill the "right side"). The closest I came was unfortunately a dead end: How to pre-populate a collection list?

In that post, it was suggested that you should be able to set list collector selections by using the standard g_form.setValue() method (http://wiki.servicenow.com/index.php?title=GlideForm_%28g_form%29#setValue), but I can't get that to work:


// This should work, according to the Wiki:
g_form.setValue('watch_list', '1', 'Michael McCall'); // assuming that '1' were actually my sys_id value

// However, having this in a catalog client script does not work:
g_form.setValue('requested_users', '1', 'Michael McCall'); // assuming that I have a list collector variable named "requested_users"

Is it just not possible to programmatically set list collector values, or is there a special method for doing so? (I might guess it has something to do with the g_filter object, but I can't find any information about that object beyond the setFilter() method.)
1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

List collector's are very different.

I think Mark Stanger's post is probably the easiest to follow;
http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
the tl;dr is that there are two functions available


moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--')
and

sortSelect(leftBucket)

These should let you move stuff around, and re-sort the left or right objects.


View solution in original post

9 REPLIES 9

Jace Benson
Mega Sage

List collector's are very different.

I think Mark Stanger's post is probably the easiest to follow;
http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
the tl;dr is that there are two functions available


moveSelectedOptions(selectedIDs, rightBucket, leftBucket, '--None--')
and

sortSelect(leftBucket)

These should let you move stuff around, and re-sort the left or right objects.


Thanks, Jace! I spent a little bit of time playing around with the scripts from Mark's page, and it looks like I can accomplish what I wanted.


I'm glad it helped. Those list collectors can be quite complicated.


Hi Jace,



I cannot open this url (http://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/), permission issue, if you can open it, could paste the script here pls?



Regards


Yogish