Stuck in UI builder Australia with typeahead component
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Dear community,
I´m trying my first steps with UI builder and got stuck at the very first beginning. I want to have an input field "typeahead" where a user can search/select from the cmn_location table. I had the hope that this is pretty much straight forward as I know it from a reference field in the catalog items.
But after checking with CoPilot and reading several web pages also here on the community I get the impression it is a bit more complicated.
I understand that I need a "look up records" data resource - ok.
I need to bind the "list items" data in the typeahead configuration to this data resource - with a script.
All the things that I found on the web were explained on Quebec or even 3 years back.
So all the scripts that were mentioned there do not work anymore, because I believe the structure changed .
I understood that the structure that the typeahead list expects can not be delivered from the data resource, so we have to make a small mapping.
A real good example I can also not find on the offical documentation.
Therefore, can someone give me a hint how the scripts should look like.
Many thanks
Best regards
Eckhard
P.S.: I am on Australia glide-australia-02-11-2026__patch3-05-25-2026
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @Eckhard ,
Below is a simple example of how I used the Typeahead component in UI Builder to display users for selection. After selecting a user, I also added an alert message as an example of how you can trigger an action based on the selection.
Steps
1. Open the UI Builder page
Open the UI Builder page and select the appropriate variant where you want to add the Typeahead component.
2. Add the Typeahead component
Add the Typeahead component to the required location on the page.
3. Add a Lookup Data Resource
After adding the component, add a Lookup Data Resource for the required table.
In my example, I am using the User (sys_user) table.
4. Add an Event Mapping
Select the data resource and navigate to the Events section.
Click Add event mapping and select the Data fetch succeeded event.
For the action, select Execute client script.
5. Configure the Client Script
The following client script updates the results returned by the Lookup Data Resource:
/**
* @param {params} params
* @param {api} params.api
* @param {any} params.event
* @param {any} params.imports
* @param {ApiHelpers} params.helpers
*/
function handler({
api,
event,
helpers,
imports
}) {
var res = api.data.look_up_multiple_records_1.results;
res.forEach(function(user) {
user.id = user._row_data.uniqueValue;
user.label = user._row_data.displayValue;
});
api.data.look_up_multiple_records_1.results = res;
}In this client script, I am adding two additional properties to each result object:
id
label
These properties are required for the Typeahead List Item configuration.
There are additional properties that can be added to the list items depending on your requirement. For this example, I am only adding the mandatory id and label properties.
Alternatively, you can create a new Client State Parameter of type JSON and store the id and labels there. In this example, I am directly using the results object from the data resource.
6. Map the Results to the Typeahead Component
Once the results have been modified, map the results object to the List items field under the Typeahead component's configuration.
You can also configure other fields, such as Selected value and Label field, depending on your requirement.
7. Handle Item Selection
If you want to perform an action after a user selects an item, go to the Events tab of the Typeahead component.
Click Add event mapping and select the Item selected event.
This event will be triggered whenever an item is selected from the Typeahead list.
You can then configure the required action, such as executing a client script, showing an alert, updating a client state parameter, or performing another UI Builder action.
I hope this example helps .
There are other events available for the Typeahead component. Please refer to the ServiceNow documentation for additional details.
Typeahead Component Documentation:
ServiceNow Typeahead Component Documentation
If you find this useful, please mark it as helpful and accept the solution.
Regards,
Harish
