Populating Catalog Fields Based on Another Field

Wasdom_Kung
Tera Guru

Hello,

I currently have 3 fields on an item:

1. Code search

2. Tray ID

3. Tray Name

I also have a custom table with 3 columns (u_nhsl_tray_codes_choices).

The user will select a code from 'code search', this code will have a tray id and tray name associated with it - I want to populated field 2 and field 3 with the corresponding column values, this way the user will see their selected code, ID and name across the 3 variables.

find_real_file.png

How can I achieve this?

1 ACCEPTED SOLUTION

Wasdom_Kung
Tera Guru

I've managed to fix this using the following  'onChange' script, and turning the 2 and 3 variables into single line texts.

function onChange(control, oldValue, newValue, isLoading) {}

var trayTable = g_form.getReference('u_rmd_and_tray_search', populateTrayID);

function populateTrayID(trayTable) {

    g_form.setValue('u_tray_id_readonly', trayTable.u_tray_id);
	g_form.setValue('u_tray_name_readonly', trayTable.u_tray_name);
}

 

View solution in original post

12 REPLIES 12

Allen Andreas
Administrator
Administrator

Hi,

You can create an onChange client script (specifying the code search variable as the field to focus on) and use GlideAjax to pass the code search value to the server, the server will lookup that record on your table and return your tray id and tray name in JSON that has been stringified, then the client will set the values of those two fields per your need.

Here's a cheat sheet to get you started: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...

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


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

Murthy Ch
Giga Sage

@Wasdom Kung 

You can use Catalog data lookup definitions here, where no code required.

Article link

 

Thanks,

Murthy

Thanks,
Murthy

Hi Murthy, 

This was a really informative find - thanks for sharing. 

I've gone through it and attempted to populate fields (set to reference as someone suggested) but they don't seem to populate.

This example should populate Tray ID based on the rmd and tray search field (I think anyway)
find_real_file.png

find_real_file.png

find_real_file.png

@Wasdom Kung 

find_real_file.png

I hope u_rmd_and_tray_search is a referene field so please replace with SysId like below screenshot:

find_real_file.png

Hope it helps

Thanks,
Murthy