- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 03:05 AM
Hello.
i have 2 fields NAME and ID
I want the ID field to be filled with the user ID of the selected user in the NAME field. so if i select john, his ID will be auto filled in the ID field.
The ID field needs to get infro from here(user_name is the id):
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 03:29 AM
Hi,
Write a onChange client script on your variable Name and add code liek this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userref = g_form.getReference('Name', userLookup);
function userLookup(userref){
g_form.setValue('ID', userref.user_name);
}
}
Mark the comment as a correct answer and also helpful if this has helped to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 03:26 AM
Hi @asd22 ,
As per the recent upgrade of ServiceNow, you can directly add a reference of the Name (Sys_user) field in the Auto-populate section of the variable "ID"
Open your "ID" variable in the Auto populate section In the Dependent Question add your "name" variable and in Reference add field which you want to auto-populate from user table.
Please mark it correct if it works for you.
Thanks,
Pratik Malviya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 03:29 AM
Hi,
Write a onChange client script on your variable Name and add code liek this.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userref = g_form.getReference('Name', userLookup);
function userLookup(userref){
g_form.setValue('ID', userref.user_name);
}
}
Mark the comment as a correct answer and also helpful if this has helped to solve the problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2023 03:30 AM