populating reference field list when another field changes

samadam
Kilo Sage

I am trying to populate a reference field values when another field changes. I have script include and calling it from catalog client script but doesnt seem to be working. When I print it is getting the right values but not setting the reference list. 

I am using the following, 

g_form.setValue('office', answer1);
 
or should I set the values differently?
 
Thank you
6 REPLIES 6

Runjay Patel
Giga Sage

Hi @samadam ,

 

If answer1 have sysid then your script should work and if you are returning name from script include then use.

g_form.setDisplayValue('office', answer1);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

I am returning array of sys_ids and want to populate the list not set one value

Hi @samadam ,

Use below script to populate the value.

 

var answer1= [
        'ee826bf03710200044e0bfc8bcbe5de6', // Replace with actual sys_id of the user
        '0e826bf03710200044e0bfc8bcbe5d7c'
       
    ];

    // Convert the array into a comma-separated string
    var watchListValue = answer1.join(',');

    // Set the value of the watch_list field
    g_form.setValue('office', watchListValue);

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

sysids are already returning as comma separated.

samadam_0-1733321675272.png