The CreatorCon Call for Content is officially open! Get started here.

Populate child Fields from Parent field record refrence

Michael_Nash
Tera Contributor

I have created a Client script for this but it does not seem to work as expected,

please see below.

 

Please assist with fixing the script 🙂

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }
    if (newValue) {
        var parent = g_form.getReference('u_parent', popParentInfo);
    }
 
    function popParentInfo(parent) {
        g_form.setValue('u_account_number', parent.account); -displays sys_id
        g_form.setValue('u_dealer_code', parent.account.u_dealer_code); - undefined
        g_form.setValue('u_dealer_name', parent.contact.name); - displays sys_id
        g_form.setValue('u_vin', parent.u_vin); - works fine
    }
}
6 REPLIES 6

manjusha_
Kilo Sage

@Michael_Nash 

 

Servicenow does not recommend usage of getReference ,you can call script include in client script using GlideAjax

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact

Thanks,

Manjusha Bangale

Nilesh Pol1
Giga Guru

Hi @Michael_Nash 

please go with following snap, it will sort your issue.

Client Script:

NileshPol1_0-1693312022613.png

 

Script Include:

NileshPol1_1-1693312064409.png

 

You can use JSON.stringify() and JSON.parse() method as you want populate multiple fields form parent.

If my answer solved your issue, please mark my answer as Correct & Helpful based on the Impact