How do you get the Choice Value from a Choice field? (not a trick question!)

Not applicable

Assume a GlideRecord, 'gr', with choice field 'os' (operating system).

How do I get the value?

gr.os.getChoiceValue() returns the 'choice label'
gr.os.getDisplayValue() returns the 'choice label'
gr.os.getElementValue() returns the 'choice label'
gr.os.getLabel() returns the 'field name'
gr.os.getValue() returns undefined

My understanding of Choice lists was that the 'label' was the human readable name and is more prone to changing to meet user tastes in spelling, wording, whatever.

And that 'value' was the ID of the choice being made and is NOT meant to be human readable.

Thanks,
Afshin

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Have you tried:

gr.os
gr.os.getValue()


So close.

gr.getValue('os') is what I have learned is the answer.


Not applicable

Just updated my post to reflect that I just tried gr.os.getValue() ~ undefined. But good guess.



CapaJC
ServiceNow Employee
ServiceNow Employee

+1 b-rad

I've always just used gr.field_name to get the value. Either of the following should also work:
gr.getValue("os");
gr.os.getElementValue("os"); //don't ask me why 🙂