- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 06:24 AM
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.
How can I achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 09:59 AM
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);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 06:31 AM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 06:31 AM
You can use Catalog data lookup definitions here, where no code required.
Article link
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 07:17 AM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2022 07:33 AM