- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 08:16 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2025 08:48 PM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 09:55 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2025 10:07 AM
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader