How to auto populate one reference field value based on other reference field on catalog item?

hemachandra2
Tera Contributor

Hi All,

Actually we have two reference fields(State , City),these two are refering to location table only, so my requirement was whenever we select city based on that state will auto populate ?

Please help me on this

Thanks

Hemachandra

8 REPLIES 8

Hi @Ankur Bawiskar 

Thanks the response

Ok if i do state as string, can you please provide the script to auto populate state based on the selection of city?

Thanks

Hemachndra

Hi,

City is reference to cmn_location table

you can use onChange client script + callback method

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

	if(newValue == ''){
		g_form.clearValue('stateField');	// state field name here
	}

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

function callBackMethod(ref){
	if(ref.state)
		g_form.setValue('stateField', ref.state); // state field name here
}

regards
Ankur

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

@hemachandra 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

@hemachandra 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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