Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get value of choice list

DerErik
Kilo Explorer

Hi @ all,

i need a client script (onchange) to manipulate a textfield ('name'). To read the value of a textfield ('city') is no problem, but how can i do this with my choice list? I need the actual selected value (or label) of the choice list.

Thank you for your help!
---------

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

//Type appropriate comment here, and begin script below
var city;
var type;

city = g_form.getValue('city');
type = g_form.getValue('type'));

g_form.setValue('name', type + ' ' + city);
}

1 REPLY 1

march
Kilo Guru

try this one:



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

var mycity = g_form.getValue('city');
var typeValue = g_form.getValue('category');
var typeLabel = g_form.getOption('type', typeValue).label;

g_form.setValue('name', typeLabel + ' ' + mycity);
}


you should catch the value of the field and then find the label corresponding to that value.