Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Accessing Choice text instead of Choice Value in flow

Nic Nagtzaam
Mega Guru

Hello,

We have a workflow where we are getting the catalog variables at the beginning of the workflow. 

after this, we want to use the variables to populate the description of a change request. this is working perfectly, with one exception. we are unable to get the Text value of a dropdown (select box/choice) instead of the choice value. 

I have tried getDisplayValue() and getLabel() both of which display undefined when being passed into the change description. 

below is a copy of the script for the description field:

var shortDesc ="Please refer to "+fd_data.trigger.request_item.number+" For full server build details. \n\n";
shortDesc +="Location: Cloud - "+fd_data._1__get_catalog_variables.location_cloud+" \n";
shortDesc +="Operating System: "+fd_data._1__get_catalog_variables.operating_system.getDisplayValue()+" \n";
shortDesc +="Instance Type: "+fd_data._1__get_catalog_variables.instance_type+" \n";
shortDesc +="C Drive: "+fd_data._1__get_catalog_variables.c_drive+" \n";
shortDesc +="D Drive: "+fd_data._1__get_catalog_variables.d_drive+" \n";
shortDesc +="Business Criticality: "+fd_data._1__get_catalog_variables.business_criticality+" \n";
shortDesc +="Cost Centre: "+fd_data._1__get_catalog_variables.cost_center+" \n";
shortDesc +="Environment: "+fd_data._1__get_catalog_variables.environment+" \n";
shortDesc +="Support Group: "+fd_data._1__get_catalog_variables.support_group.name+" \n";

return shortDesc;

Operating System is the problem here on line 3 of the script. 

Any advice would be greatly appreciated. 

Regards

Nic Nagtzaam

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you sure your Get Catalog Variables Action has the variable included in it

operating_system

If that doesn't work use this

var ritmSysId = fd_data.trigger.request_item.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);
var variableDisplayValue = rec.variables.operating_system.getDisplayValue();

var shortDesc ="Please refer to "+fd_data.trigger.request_item.number+" For full server build details. \n\n";
shortDesc +="Location: Cloud - "+fd_data._1__get_catalog_variables.location_cloud+" \n";
shortDesc +="Operating System: "+ variableDisplayValue +" \n";
shortDesc +="Instance Type: "+fd_data._1__get_catalog_variables.instance_type+" \n";
shortDesc +="C Drive: "+fd_data._1__get_catalog_variables.c_drive+" \n";
shortDesc +="D Drive: "+fd_data._1__get_catalog_variables.d_drive+" \n";
shortDesc +="Business Criticality: "+fd_data._1__get_catalog_variables.business_criticality+" \n";
shortDesc +="Cost Centre: "+fd_data._1__get_catalog_variables.cost_center+" \n";
shortDesc +="Environment: "+fd_data._1__get_catalog_variables.environment+" \n";
shortDesc +="Support Group: "+fd_data._1__get_catalog_variables.support_group.name+" \n";

return shortDesc;

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

are you sure your Get Catalog Variables Action has the variable included in it

operating_system

If that doesn't work use this

var ritmSysId = fd_data.trigger.request_item.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);
var variableDisplayValue = rec.variables.operating_system.getDisplayValue();

var shortDesc ="Please refer to "+fd_data.trigger.request_item.number+" For full server build details. \n\n";
shortDesc +="Location: Cloud - "+fd_data._1__get_catalog_variables.location_cloud+" \n";
shortDesc +="Operating System: "+ variableDisplayValue +" \n";
shortDesc +="Instance Type: "+fd_data._1__get_catalog_variables.instance_type+" \n";
shortDesc +="C Drive: "+fd_data._1__get_catalog_variables.c_drive+" \n";
shortDesc +="D Drive: "+fd_data._1__get_catalog_variables.d_drive+" \n";
shortDesc +="Business Criticality: "+fd_data._1__get_catalog_variables.business_criticality+" \n";
shortDesc +="Cost Centre: "+fd_data._1__get_catalog_variables.cost_center+" \n";
shortDesc +="Environment: "+fd_data._1__get_catalog_variables.environment+" \n";
shortDesc +="Support Group: "+fd_data._1__get_catalog_variables.support_group.name+" \n";

return shortDesc;

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader