The CreatorCon Call for Content is officially open! Get started here.

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

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;

 

Hi @apjohn2 ,

 

I had the same problem, thanks for pointing to the KB article.

I solved it differently, by using the getDisplayValue() function of the RITM/SC Task. Maybe interesting for others that read this post.

 

I created a flow action, with the RITM and Task as input + the question/variable.

 

var grTask = !gs.nil(inputs['ritm']) ? inputs['ritm'] : inputs['sc_task'];
  if(!gs.nil(grTask)){
    var variableName = 'variables.' + inputs['variable_name'];
	outputs['displayvalue'] = grTask.getDisplayValue(variableName);
  }

 

This makes it generic, so you can re-use it in every flow.

 

Regards,

Hayo

Hi Hayo,

 

I'm having trouble replicating what you did - do you mind sharing the details of the action you created?

Hello,

Were you able to get the answer to this?

Thanks,

Chad