populating reference field list when another field changes

samadam
Mega 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

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

Here in this Video, I have covered the Basic of ITOM and CMDB as well as Introduction about the ITOM Module. Thank you for visiting my channel. Here, I'll share various technical knowledge. Feel free to reach out to me directly for any Service Now-related queries. Your support encourages me to ...

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

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

Here in this Video, I have covered the Basic of ITOM and CMDB as well as Introduction about the ITOM Module. Thank you for visiting my channel. Here, I'll share various technical knowledge. Feel free to reach out to me directly for any Service Now-related queries. Your support encourages me to ...

sysids are already returning as comma separated.

samadam_0-1733321675272.png