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

Hi,

So how many values are there for this record for Sub ID?

Regards
Ankur

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

Community Alums
Not applicable

In most cases, there will be just 1 value however, in some cases, a company can have many values within the Sub ID.  It isn't a choice list; users manually enter a value(s) in the Manual Sub ID and when he/she saves the record, they are stored in the Sub ID.

 

I've tried the approach to query the core_company table and that returned the value I needed!

 

@Michael Coletti 

Glad to help.

Please mark response as correct and helpful.

Regards
Ankur

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

I've seen this solution offered before but WHERE are you putting this?

I'm using an HTML field with Data pills.  If I script this field it does not do what I need

 

find_real_file.png     

simonluu
Kilo Explorer

How do you access the fd_data variables in Flow Action?

I tried your example: 

(function execute(inputs, outputs) {
// ... code ...
var account_name= fd_data.trigger.request_item.variables.account_name;


gs.info('Account Name is: [' + account_name+ ']');


})(inputs, outputs);

I'm getting this error: 

Error: "fd_data" is not defined.,Detail: "fd_data" is not defined. 

Any ideas?