Auto populate a field which depends on the field present in an another table.

1_DipikaD
Kilo Sage

Hi All,

I have a reference field called "app name"on a custom table which refers to business application table.
Also i have a field called region which refers to cmn_location table in Business application table.
Another region field also present in custom table which value depends on the region of "app name" selected.
I want to auto populate region field in custom table with the same value of region field with respect to
the app name selected in the custom table.

 

Thank you 

1 ACCEPTED SOLUTION

@1_DipikaD 

something like this using 2nd approach

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == '') {
        g_form.clearValue('regionFieldCustomTable'); // region field on custom table
    }

    var ref = g_form.getReference('appNameField', callBackMethod); // app name field name
}

function callBackMethod(ref) {
    if (ref.regionField) // give the region field present on business app table
        g_form.setValue('regionFieldCustomTable', ref.regionField); // give the region field present on business app table
}

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

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@1_DipikaD 

2 options

1) show the Region field from the business app table as dot walked field -> why to create a new field to show Region

OR

2) use onChange client script with getReference callback and fetch and set the region field

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

@1_DipikaD 

something like this using 2nd approach

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

    if (newValue == '') {
        g_form.clearValue('regionFieldCustomTable'); // region field on custom table
    }

    var ref = g_form.getReference('appNameField', callBackMethod); // app name field name
}

function callBackMethod(ref) {
    if (ref.regionField) // give the region field present on business app table
        g_form.setValue('regionFieldCustomTable', ref.regionField); // give the region field present on business app table
}

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

@1_DipikaD 

Hope you are doing good.

Did my reply answer your question?

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

@1_DipikaD 

any update to this?

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