Add specific users to a List Collector

ceraulo
Mega Guru

Hello!

I have a catalog item with a list collector variable.

I want to populate this variable with specific users (ex. User A, User B, User C). I've tried using the below (Catalog Client Script) using system properties but it does not work.

function onSubmit() {    
        g_form.setValue('list_collector_variable', 'sysprop_sysid1, sysprop_sysid2, sysprop_sysid3');
}

Please help!

Thank you.

1 ACCEPTED SOLUTION

@ceraulo 

store the comma separated sysIds in system property and use it

javascript: gs.getProperty('propertyName');

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

8 REPLIES 8

Hi,

then why not set based on Change of variable instead of onSubmit?

where are you running this script? Native OR Portal

for portal it should work on change of variable

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Have you considered Catalog Data Lookup Rules? The same can be obtaines with no code at all:

find_real_file.png

As soon as someone selects the right reference, the system fetches the data and places it into list_collector_variable.

E.g. I have created table u_dl_location_users extending Data Lookup Matcher Rules (so it will be license "free"):

find_real_file.pngI have added two records:

find_real_file.pngHave configured the lookup rules:

find_real_file.pngThis tells the system that whenever variable location can be located in column u_location in the lookup table, it should take the value of field u_user and place it into variable users. Yeah, calling a target source variable, is confusing.

Under the circumstances, if one chooses "Washingtom D.C." as location, the user list is automatically filled in by the system:

find_real_file.png

If the other location is chosen, the matching user list is filled in:

find_real_file.png

A bit more work upfront (have to create a table and configure data lookup), but easy to maintain.

dmathur09
Kilo Sage
Kilo Sage

Hi Ceraulo,

Having a default value is a better approach as you are using it just before the submission.

To your client script you can update it as below to make it work.

function onSubmit() {   
var arr = [];
arr =  'sysprop_sysid1, sysprop_sysid2, sysprop_sysid3'
        g_form.setValue('list_collector_variable',arr.toString);
}

Regards,

Deepankar Mathur

Abhijit4
Mega Sage

Hi,

You cannot access system property directly in client script, your would need to get those values through GlideAjax.

Let me know if you have any further queries.

Please mark this as Correct or Helpful if it helps.

Thanks and Regards,
Abhijit
Community Rising Star 2022

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP