AutoPopulate fields on a form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 06:26 AM
Hello All,
I have a requirement to auto-populate fields (org_ap, p_tech_ap, po_a, o_a, p_ta) on contract_partner table's form when field u_partner is changed based on if a record with similar value (u_company) already exist in customer_inforamtion table. The u_partner field and u_company are both reference fields (core_company).
How can I achieve this.. ?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 08:10 AM
your script include is not client callable
Also the way how function is accepting value is incorrect.
Your GlideAjax syntax is also wrong
You can refer my below script which uses getReference with callback
That should also work once you use correct field names etc
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-06-2025 06:33 AM
these fields org_ap, p_tech_ap, po_a, o_a, p_ta are to be populated from which fields of core_company table
something like this in onChange of u_partner field and set the correct fields and fetch the correct fields from core_company
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.clearValue('org_ap');
g_form.clearValue('p_tech_ap');
g_form.clearValue('po_a');
g_form.clearValue('o_a');
g_form.clearValue('p_ta');
}
var ref = g_form.getReference('u_partner', callBackMethod); // requestedFor variable name
}
function callBackMethod(ref) {
if (ref.orgField)
g_form.setValue('org_ap', ref.orgField);
if (ref.pTechField)
g_form.setValue('p_tech_ap', ref.pTechField);
if (ref.poaField)
g_form.setValue('po_a', ref.poaField);
if (ref.oaField)
g_form.setValue('o_a', ref.oaField);
if (ref.ptaField)
g_form.setValue('p_ta', ref.ptaField);
}
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