State visible according to country variable in form

SimranS04382950
Tera Contributor

SimranS04382950_0-1748251189790.png

I have this form in record producer , shipping country and shipping state -> select look up type -> referencing to "cmn_location" table.

I want state and city to comes according to selected country.

i.e. if i select "INDIA" in shipping country then state of India should be visible in "shipping state" variable.

9 REPLIES 9

Understood and sorry for missing that aspect. Perhaps, do a query then like this:

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

    // Clear the shipping state field
    g_form.setValue('shipping_state', '');

    g_form.setQuery('shipping_state', 'country=' + newValue);
}

 

SuyashJ41731830
Tera Contributor

Hi
@SimranS04382950 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
// Clear state options on load or if country is cleared
g_form.clearOptions('shipping_state');
return;
}

// Set reference qualifier on shipping_state to only show states whose parent is the selected country sys_id
var filter = 'parent=' + newValue;
g_form.setFilter('shipping_state', filter);

// Clear shipping_state value so user can re-select appropriate state
g_form.setValue('shipping_state', '');
}

onChange Client Script
Thanks, and Regards,
Suyash

Ankur Bawiskar
Tera Patron
Tera Patron

@SimranS04382950 

you can use script for this

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.

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

SimranS04382950_0-1748351728451.png

I have tried to use this reference qualifier, but this didn't work.

Ashish Parab
Mega Sage

Hello @SimranS04382950,

 

You can simply use a reference qualifier as below:

Reference qual - javascript&colon; '<enter your country field name from cmn_location table>='+current.variables.shipping_country;

 

AshishParab_0-1748355031480.png

 

Output -

AshishParab_0-1748354825734.png

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish