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.

Ho to Get the Text Value of Multiple choice Variable in On Change Client Script

cvenu
Tera Contributor

Hi,

How to Get the Text Value of Multiple choice Variable in On Change Client Script as below

find_real_file.png

When using the below code in onChange Script

  var modelval = g_form.getValue('APAC_EMEA_dell_Laptop');

i am getting the Value "Dell E7390 (Small Laptop)" in modelval 

i meed to get text as "Dell Latitude 7300" in modelval .

Please suggest .

Thanks

Venu

 

 

 

4 REPLIES 4

Community Alums
Not applicable

Hi Venu,

if its not for portal CSJD should be fine. Try with
var fld =g_form.getControl('your field here);

var txt = fld.txt (or it was "value", cant remeber )

 

Let me know if it is not doing the magic

 

Cheers,

Joro

Ankur Bawiskar
Tera Patron
Tera Patron

@cvenu 

g_form.getValue() will give you the choice value and not label.

The below script worked well for me in Native

Script:

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

	var value = g_form.nameMap;
	var parser = JSON.parse(JSON.stringify(value));
	var label = '';
	for(var i=0;i<parser.length;i++){
		if(parser[i].prettyName == newValue){
			label = parser[i].label;
			break;
		}
	}
	alert(label);

}

find_real_file.png

Output:

find_real_file.png

Regards
Ankur

 

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

@cvenu 

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

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

sachin_namjoshi
Kilo Patron
Kilo Patron

You below Get the label for a choice list value


var choiceLabel = g_form.getOption(<fieldName>, choiceValue).text;

Regards,
Sachin