autoppulation of fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 05:41 AM
how to write client script and script include to autopopulate 2 fields at a time by selecting one field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 06:49 AM - edited 07-20-2025 06:54 AM
@seshagirirao,
Please follow my below answer : When select caller according to phone and email id will be populated automatically.
Onchange Client script :
Var userDet = new GlideAjax ("TestScript"); //name of the script include
userDet.addParam('sysparam','userdetails'); // 'userdetails' method name
userDet.addParam('sysparam_sysid', newvalue); //select field
userDet.getXML(ajaxresponse);
function ajaxresponse(response)
{
var answer = response.responseXML.documentElement.getAttribute('answer');
var userdetails = JSON.Parse(answer);
g_form.setValue('caller_phone', userdetails.phone);
g_form.setvalue('caller_email',userdetails.email);
}
}
Script include:
"check" client callable option in Script Include.
Please mark helpful and correct answer if it's worthy for you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2025 06:54 AM
Hi @seshagirirao ,
Do you need really need script include(Any info needed from Server side)??? if its straight forward to set fields use below onChange client script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//When Field changes and its not empty
if (newValue) {
g_form.setValue("Field_Name1", value1);
g_form.setValue("Field_Name2", Value2);
}
//Type appropriate comment here, and begin script below
}
Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 10:44 PM
Hi @seshagirirao,
Did you get a chance to look my previous answer ?
Please mark helpful and correct answer if it's helpful for you and to assist others in the community as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2025 10:53 PM
it's an easy requirement which you can achieve using onChange + GlideAjax
what did you start with and where are you stuck?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader