How to get display value of select box variable in flow designer?

apjohn2
Mega Sage

Hi everyone. Will try to keep this succinct.

 

Context: Service Catalog Flow > Create Catalog Task > Short Description > script >

I need to get the display value of a select box variable choice to help populate short description. I cannot get this value. I have tried "getDisplayValue" and "getLabel" functions and both return "undefined".

 

NOTE: I have looked in community but only find answers for what is apparently old functionality in Flow scripts, e.g., "fd_data.trigger.current.variables..." etc., but that no longer works because "variables" is not an option any longer from the trigger record. We therefore are using "fd_data._1__get_catalog_variables..." instead.

 

This is the non-functional script:

var sfuser = fd_data._1__get_catalog_variables.shop_floor_user;
var removeAllOrSome = fd_data._1__get_catalog_variables.remove_all_or_some.getDisplayValue();
gs.info(removeAllOrSome);

var sdesc = sfuser ? "Remove access - Mobile Device Login Only" : "Remove ERP access - " + removeAllOrSome;

return sdesc;

 

Please advise if you know how to do this; thank you!

1 ACCEPTED SOLUTION

apjohn2
Mega Sage

Somehow my search skills kicked in and I was able to find this:

KB0960074

 

That basically says you can't get display values for select box choices in Flow designer and you have to look them up in the script, so that's what I did. Here is the updated script, which works fine:

var sfuser = fd_data._1__get_catalog_variables.shop_floor_user;
var removeAllOrSome = fd_data._1__get_catalog_variables.remove_all_or_some;

/*
Next, we have to use glide record query to Look up the display value for the selected 'remove_all_or_some' choice
Ref: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0960074
*/
var qc = new GlideRecord('question_choice');
qc.addQuery('question','a7509b79db10589005c96ce2ca961997');
qc.addQuery('value',removeAllOrSome);
qc.query();
if (qc.next()) {removeAllOrSome = qc.text;}

var sdesc = sfuser ? "Remove access - Mobile Device Login Only" : "Remove ERP access - " + removeAllOrSome;

return sdesc;

 

View solution in original post

7 REPLIES 7

Hi @gjz , @purdue ,

 

Sorry I missed the earlier response. Attached an XML of a global action to retrieve the variable displayValue.

 

Regards,

Hayo

M-Gren
Tera Contributor

I have tried playingaround with this since I would like to return the Variable.Text and not the Variable.Value in a record producer.
As far as I can see the question Sys_id is uniq for each choice in the select box variable, which makes this very cumbersome if I have a select box with (for instance) 10 choices, which if I understand this correctly leaves me with hardcoding 10 seperate combinations of Value and Question SysIDS..
Any input or ideas on how to obtain, what I am looking for , would be much apreciated 🙂

 

Al I want is to be able to return the Label (of the selected choice) from a select box type variable (on a incident record producer), because I want to include the selected (Value's Label) in the description field on the incident.

Hello,

What inputs and outputs did you use?

Thanks,

Chad