Custom Action in the Service Now Flow Designer

Sagar Rd
Tera Contributor

Hi All,

 

I am working on a requirement, trying build a custom action and the Input Action I have a input with the type List.Core_country and then I am trying to use that values in the script but the below script is not extracting the values insted it throwing the error as "Selected Countries[object GlideRecord]". Please help me how to fetch the list values as input to the script

 

(function execute(inputs, outputs) {

    var selectedCountries = inputs.to;
    gs.info('Selected Countries'+selectedCountries);
   

})(inputs, outputs);
 
Thanks
Mourya
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sagar Rd 

since it's list of GlideRecord you can iterate like this and get the name and story in array

This will work fine

(function execute(inputs, outputs) {

    var selectedCountries = inputs.to;

    var countryArray = [];
    // iterate the object
    while (selectedCountries.next()) {
        countryArray.push(selectedCountries.name.toString());
    }
    gs.info('Selected Countries' + countryArray.toString());

})(inputs, outputs);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @Sagar Rd ,

You need to fetch the actual value from the GlideRecord.
For example, if you want the Name or Country Code of the selected country, you have to use selectedCountries.field_name.

 

try this 

(function execute(inputs, outputs) {

    var selectedCountries = inputs.to;
    
    // Assuming you want the 'name' field from Core_country table
    if (selectedCountries) {
        gs.info('Selected Country Name: ' + selectedCountries.name);
        gs.info('Selected Country Sys ID: ' + selectedCountries.sys_id);
    } else {
        gs.info('No country selected.');
    }

})(inputs, outputs);

 

  • selectedCountries.name → gets the country name.

  • selectedCountries.sys_id → gets the system ID of the selected record.

 

Hi @Community Alums 

 

I have used the same script, but no response I have received.

 

(function execute(inputs, outputs) {

    var selectedCountries = inputs.to;
    if (selectedCountries) {
        gs.info('Selected Country Name: ' + selectedCountries.name);
        gs.info('Selected Country Sys ID: ' + selectedCountries.sys_id);
    } else {
        gs.info('No country selected.');
    }
   

})(inputs, outputs);

Ankur Bawiskar
Tera Patron
Tera Patron

@Sagar Rd 

since it's list of GlideRecord you can iterate like this and get the name and story in array

This will work fine

(function execute(inputs, outputs) {

    var selectedCountries = inputs.to;

    var countryArray = [];
    // iterate the object
    while (selectedCountries.next()) {
        countryArray.push(selectedCountries.name.toString());
    }
    gs.info('Selected Countries' + countryArray.toString());

})(inputs, outputs);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

 

Solution worked for me.

 

Thankyou