- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
I set up a Catalog Data Lookup Definition for a catalog item so that the employee ID, job title, and email address auto-populate based upon the requester that opens the request. My issue is that when the form loads, those fields don't populate. However, I found that if select a different name, then those fields do populate. The Requester Name is defined as a reference field and in the type specification tab, the reference table is [sys_user]. What am I doing wrong? How do I get the above fields to populate for the person opening the catalog item?
While trying different things, I set a default value of "javascript: gs.getUserID();" for the Requester Name field and then it populates when the request is opened. Do I have to add javascript to the rest of the fields so they populate when the catalog item is opened? Any insight would be greatly appreciated. Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Mike LHCG1 ,
This is actually expected behavior for Catalog Data Lookup Definitions.
The Reason: The Data Lookup engine is primarily triggered by an onChange event. It waits for the "Matcher" variable (Requester) to actively change values in the browser to fire the lookup. When the form first loads, even if the Requester is set by default, the lookup engine doesn't always "see" this as a change event, so the dependent fields remain empty until you manually toggle the name.
The Solution: Use Default Values Since your goal is to populate information for the Current User (the person opening the item), you don't actually need a Data Lookup for the initial load. You can set this directly in the Default Value tab of each variable.
This is faster (no server lookup needed) and works immediately on load.
Here are the scripts to put in the Default Value field for each variable:
Requester: javascript:gs.getUserID(); (You already did this)
Email: javascript:gs.getUser().getEmail();
Job Title: javascript:gs.getUser().getRecord().getValue('title');
Employee ID: javascript:gs.getUser().getRecord().getValue('employee_number');
How it works together:
On Load: These scripts run and populate the form with the logged-in user's data instantly.
On Change: If you change the Requester to someone else, your existing Data Lookup Definition will kick in (since it's an onChange event) and update the fields for the new person.
This gives you the best of both worlds!
If this response helps you solve the issue, please mark it as Accepted Solution.
Best regards,
Brandão.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi @Mike LHCG1 ,
This is actually expected behavior for Catalog Data Lookup Definitions.
The Reason: The Data Lookup engine is primarily triggered by an onChange event. It waits for the "Matcher" variable (Requester) to actively change values in the browser to fire the lookup. When the form first loads, even if the Requester is set by default, the lookup engine doesn't always "see" this as a change event, so the dependent fields remain empty until you manually toggle the name.
The Solution: Use Default Values Since your goal is to populate information for the Current User (the person opening the item), you don't actually need a Data Lookup for the initial load. You can set this directly in the Default Value tab of each variable.
This is faster (no server lookup needed) and works immediately on load.
Here are the scripts to put in the Default Value field for each variable:
Requester: javascript:gs.getUserID(); (You already did this)
Email: javascript:gs.getUser().getEmail();
Job Title: javascript:gs.getUser().getRecord().getValue('title');
Employee ID: javascript:gs.getUser().getRecord().getValue('employee_number');
How it works together:
On Load: These scripts run and populate the form with the logged-in user's data instantly.
On Change: If you change the Requester to someone else, your existing Data Lookup Definition will kick in (since it's an onChange event) and update the fields for the new person.
This gives you the best of both worlds!
If this response helps you solve the issue, please mark it as Accepted Solution.
Best regards,
Brandão.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Itallo,
Would each of those fields be defined as reference or single line text fields?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Thanks Itallo, I appreciate it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
You are very welcome, Mike! Glad I could help.
If you'd like to stay connected for more ServiceNow tips, feel free to reach out or follow me on LinkedIn.
https://www.linkedin.com/in/itallobrandao/
Have a great weekend!
Brandão.
