Flow Designer - Inline scripting: Get display values from List field

Community Alums
Not applicable

Does anyone know how to get the display values from a List field within an inline script in Flow Designer?

Here is the information:

-  List field is on the core_company field called "u_sub_id"

-  The flow runs against a catalog item that contains a reference variable (called "customer") that references [core_company]

-  Within the inline script, I want to return the first entry in the List field into a variable.  Since the variable references core_company, I can dot-walk to the "u_sub_id" field.  However, when I print out the results of the variable to the log, it is returning "object GlideRecord". 

Here are some of the things I've tried in the inline script:

var test2 = fd_data.trigger.request_item.requested_for.company.u_sub_id.toString();
gs.info("Test2: " + test2);    // returns "[object GlideRecord]"

// _2__update_record is updating the RITM record
var list = fd_data._2__update_record.record.requested_for.company.u_sub_id.toString();
gs.info("subID: " + list);  // returns "[object GlideRecord]"
 
 
Any help would be greatly appreciated.
 
1 ACCEPTED SOLUTION

Hi,

how the values in the list field looks like?

So are you saying it is only returning only the 1st choice

can you share the image how many choices that list field has

As an alternative can you try this

return fd_data._1__get_catalog_variables.customer.u_sub_id.getValue();
 
OR
 
Query the core_company table with this sys_id and get the value
 
var rec = new GlideRecord('core_company');
rec.addQuery('sys_id', fd_data._1__get_catalog_variables.customer);
rec.query();
if(rec.next()){
return rec.u_sub_id;
//OR
return rec.u_sub_id.getValue();
// OR
return rec.u_sub_id.getDisplayValue();

}

Regards
Ankur

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

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

this worked well for me for getting display value of list collector variable

return fd_data.trigger.request_item.variables.my_user.getDisplayValue();

for your case update as this

var val = fd_data.trigger.request_item.variables.customer.u_sub_id.getDisplayValue();

Regards
Ankur

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

Community Alums
Not applicable

Hi Ankur,

 

I simplified my flow so it has a "Get Catalog Variables" and a "Log" actions.  Within the Log action, I have the following in the inline script:

 

return fd_data._1__get_catalog_variables.customer.u_sub_id.getDisplayValue();
 
and it is returning "Created".  I was expecting the first entry in the List value (c86c0fcf-daa7-4c63-894a-a4f5c98fda7a)
 
 
The List field I have is unique in the sense that it is not a reference list field.  I have it setup that users enter a string in a text box and when the user clicks Save, it takes the value from the string value and stores it into the List field.
 

Hi,

how the values in the list field looks like?

So are you saying it is only returning only the 1st choice

can you share the image how many choices that list field has

As an alternative can you try this

return fd_data._1__get_catalog_variables.customer.u_sub_id.getValue();
 
OR
 
Query the core_company table with this sys_id and get the value
 
var rec = new GlideRecord('core_company');
rec.addQuery('sys_id', fd_data._1__get_catalog_variables.customer);
rec.query();
if(rec.next()){
return rec.u_sub_id;
//OR
return rec.u_sub_id.getValue();
// OR
return rec.u_sub_id.getDisplayValue();

}

Regards
Ankur

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

Community Alums
Not applicable

I think your approach with querying the company table might be the best approach.  I'm going to try it.

 

Here is a screenshot of a company record with the Sub ID:

find_real_file.png