Catalog data lookup definition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 03:12 AM
I am trying to write a catalog data lookup definition. If a user is logged in then it will auto populate their business unit and location. But it is only working in on change. It is not working for on load. Does catalog data lookup definition not work for on load?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 03:53 AM - edited ‎03-05-2024 04:40 AM
Catalog Data Lookup Definitions do not work onLoad. If your instance is on the Utah or later version, try the Variable Auto-populate feature
Pre-Utah you can use an onLoad Catalog Client Script which uses supported methods of getReference
or GlideAjax
to return the related field values based on the variable value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 12:27 AM
Thank you very much.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 04:02 AM
In ServiceNow, the Catalog Data Lookup Definitions are designed to work with onChange events, not onLoad events. This is because data lookup definitions are primarily intended to populate fields based on a change in another field.
To resolve this issue, you can use a Client Script. This script will execute when the form loads (onLoad) and will populate the fields with the logged-in user's business unit and location. Here's a simple example of how you can do this:
function onLoad() {
// This script runs when the form loads
if (g_form.isNewRecord()) { // Checks if the form is a new record
var userID = g_user.userID; // Gets the logged-in user's ID
var gr = new GlideRecord('sys_user'); // Creates a new GlideRecord on the 'sys_user' table
if (gr.get('user_name', userID)) { // If the user exists in the 'sys_user' table
g_form.setValue('business_unit', gr.getValue('business_unit')); // Sets the 'business_unit' field to the user's business unit
g_form.setValue('location', gr.getValue('location')); // Sets the 'location' field to the user's location
}
}
}
This script uses the GlideRecord API to retrieve the logged-in user's business unit and location from the 'sys_user' table. It then populates the 'business_unit' and 'location' fields on the form with these values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2024 12:26 AM
Thank you.