Need to Set a value on single line text variable based on other variable selected choice.

varma2
Mega Sage

Hi All,

 

We have multi choice variable called (service ) in that we have multiple choices. if the choice contains 'SP', we need to set a other variable single line text value as ''123'', if the choice contains 'ORACLE,' we need to set a other variable single line text value as ''456'',.

 

Please suggest,

Thanks All.

 

1 ACCEPTED SOLUTION

Hi,

update as this

function onChange(control, oldValue, newValue, isLoading) {

	if (isLoading || newValue == '') {
		return;
	}

	var service = g_form.getValue("vic_ServiceTier");

	if(service.indexOf('SQL') > -1){
		g_form.setValue("vic_PortNumber", "1433");
	}
	else if(service.indexOf("Oracle") > -1){
		g_form.setValue("vic_PortNumber", "1521");
	}

}

Regards
Ankur

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

View solution in original post

7 REPLIES 7

Aman Kumar S
Kilo Patron

You wanna write onchange client script on the service field

your code should look something like:

var service = g_form.getValue("service");

if(service == 'SP'){

g_form.setValue("field_name_1", "123");

}

if(sevice == "ORACLE"){

g_form.setValue("field_name_2", "456");

}

Best Regards
Aman Kumar

Hi Kumar,

Thanks for reply.

 

I have implemented above script but its not working. in this script we mentioned if(service == 'SQL')

But its not equal it should be contains.

 

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {
return;
}

var service = g_form.getValue("vic_ServiceTier");

if(service == 'SQL'){

g_form.setValue("vic_PortNumber", "1433");

}

if(sevice == "Oracle"){

g_form.setValue("vic_PortNumber", "1521");

}

}

  Please suggest.

 

Thanks,

If is multiselect then you have to use indexOf, sorry didn't notice it before:

But what about the scenarios, where you have both SQL and Oracle selected,

Make sure to properly map the field names while populating values.

I think Ankur's script should help

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Should be simple enough with Catalog Client Script onChange of Multi choice variable

what have you started and where are you stuck?

Regards
Ankur

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