We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

@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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

HI @Ankur Bawiskar 

 

So when I have added this action on to the flow, and I have attached the List Field(core_country) for the input to the flow, and It actually working as expected if 2 or more countries selected, but if we select only one country it not working as expected. Could you please help me where am I missing it.

 

Thankyou

@Sagar Rd 

check in the action script how many objects are there and based on that iterate

something like this

(function execute(inputs, outputs) {
    var countryArray = [];
    var selectedCountries = inputs.to;
    if(selectedCountries.getRowCount() == 1){
// use this
selectedCountries.next();
countryArray.push(selectedCountries.name.toString());
}
else{
    // 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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader