AutoPopulate fields on a form

Afzal Gul
Tera Contributor

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

6 REPLIES 6

@Afzal Gul 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

@Afzal Gul 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader