- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 02:37 AM
I have a form which has a reference field - USER (sys_user)
This form has other fields like - First name, Last name, Manager (all these are read only fields)
When a user chooses from USER, other fields must populate automatically. How can I do this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 03:14 AM
Hello Vidhya,
You can either dot walk the fields as shown below link.
or else if you want to do scripting, you can use GlideAjax api as per below
var caller=g_form.getValue('caller');
var ga=new GlideAjax('script_include_name');
ga.addParam('sysparm_name', 'getDetails'); //function name 'getDetails'.
ga.addParam('sysparm_value', caller); //pass caller parameter
ga.getXML(getValue); //response async call
write script include with the function getDetails and apply logic , do gliderecord for user table and retrieve all your return values in one JSON.
function getValue(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
}
get that response from script include in JSON , so that you can autopopulate your fields as below,
g_form.setValue('first_name',answer.firstName);
g_form.setValue('last_name',answer.lastName);
If you want to know the logic of GlideAjax you can refer the link below.
https://docs.servicenow.com/bundle/tokyo-application-development/page/script/ajax/topic/p_AJAX.html
Please mark me correct or helpful if you satisfied with my answer.
Thank you.
Vallabh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 02:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 03:14 AM
Hello Vidhya,
You can either dot walk the fields as shown below link.
or else if you want to do scripting, you can use GlideAjax api as per below
var caller=g_form.getValue('caller');
var ga=new GlideAjax('script_include_name');
ga.addParam('sysparm_name', 'getDetails'); //function name 'getDetails'.
ga.addParam('sysparm_value', caller); //pass caller parameter
ga.getXML(getValue); //response async call
write script include with the function getDetails and apply logic , do gliderecord for user table and retrieve all your return values in one JSON.
function getValue(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
}
get that response from script include in JSON , so that you can autopopulate your fields as below,
g_form.setValue('first_name',answer.firstName);
g_form.setValue('last_name',answer.lastName);
If you want to know the logic of GlideAjax you can refer the link below.
https://docs.servicenow.com/bundle/tokyo-application-development/page/script/ajax/topic/p_AJAX.html
Please mark me correct or helpful if you satisfied with my answer.
Thank you.
Vallabh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-28-2023 04:07 AM
Hi @vidhya_mouli ,
You don't need to create and use custom fields for this, you can simply dot walk and add fields to the form.
Go to > Form < Additional actions > Configure > Form Layout
Select the reference field and click on expand reference field, than add the field you required in the form.
If you want to use the custom field, you can do this by creating client script and script include.
I am adding script for your reference.
If this helps you in solving your problem, mark this as correct & helpful.
Regards
Anand