Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

g_form get label of choice

xiaix
Tera Guru

I have a string field on a form that has a choice list.

find_real_file.png

It's the "Label" of the choice list that I want:

find_real_file.png

If I do g_form.getLabelOf('u_computer_type'), of course it will return:   Computer Type

What trickery can I do to get the label of the chosen choice?

1 ACCEPTED SOLUTION

marcguy
ServiceNow Employee

4.8.10 Get the label for a choice list value

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

View solution in original post

4 REPLIES 4

marcguy
ServiceNow Employee

4.8.10 Get the label for a choice list value

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

Great, very useful.

Unfortunately, g_form.getOption() doesn't work with Service Portal ( for now ...)

There is a topic with @Chuck and @Brad about it here : g_form.getOptions not working in the portal. alternative

 

xiaix
Tera Guru

Freaking genius.   Thank you!


jacque3
Kilo Guru
var choiceValue = g_form.getValue(<fieldName>); 
var choiceLabel = g_form.getOption(<fieldName>, choiceValue).text;
is no longer working in the current Service Portal, you can use this instead;
var valueLabel = g_form.getDisplayValue(<fieldName>);