Scripting for Email Notifications - Getting the display value of a choice list

richard_selby
Kilo Guru

I'm having trouble with getting a the display value of a choice list into my mail template. Can anyone help me with the correct syntax? You think it would be getDisplayValue() but that doesn't do it.


What I want to see in my resolved template:
Dear Customer,
We have closed your incident with the following reason:
Customer- Configuration-Polite Customer Facing Phrase-another one

What I get:
Dear customer
We have closed your incident with the following reason:
cu-conf-pcfp-anoth

Below is a mail script snipped of what I have tried for the left hand variable (close code level 1), and what it prints

template.print( current.u_close_code_l1.getLabel() + "-" // Displays the field label, Close Code L1
+ current.u_close_code_l1.getDisplayValue() + "-" // displays cu which is NOT the display value, it's the value
+ current.u_close_code_l1.getValue() + "-" // undefined
+ current.u_close_code_l1 + "-" // displays cu again
)


There's a huge choice of labels/values over four levels of close codes, with lots of repetition, so I need the database values to be distinct, hence the cu conf npp style values. So I can't just make the values and labels the same on the choice list.

So what's the magic mail script line to print the display value, not the value?

7 REPLIES 7

rahul_garg
Kilo Expert

Can you try this


gs.log(current.impact.getDisplayValue());
gs.log(current.impact.getChoiceValue());
gs.log(current.impact.getLabel());
var value = current.impact.getDisplayValue();

template.print( current.u_close_code_l1.getLabel() + "-" // Displays the field label, Close Code L1
+ current.u_close_code_l1.getDisplayValue() + "-" // displays cu which is NOT the display value, it's the value
+ value + "-" // undefined
+ current.u_close_code_l1 + "-" // displays cu again
)


scotthal
Mega Expert

.getChoiceValue();

I just needed to figure this out from some jelly code.

http://wiki.servicenow.com/index.php?title=GlideElement#getChoiceValue.28.29


Thanks for sharing Scott, I have had this same issue.