- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 11:46 PM
I have a look up select box variable in MRVS for selecting multiple countries at a time. I'm trying to create task in workflow according to some condition
- if user select country Cuba||Canada in the MRVS the catalog task should not create
- if user select both Cuba && Canada only, then also catalog task should not create
- But, if user select any other country along with Cuba or Canada then Catalog task should create
eg : country = Cuba and canada-> No Catalog Task
country = Cuba --> No Catalog task
country = India ---> Create Catalog Task
country = India,Cuba --> Create Catalog task
How to achieve this in servicenow workflow
I have written a if condition code but it is only checking the first row .how i will loop through all the country selected and check the condition?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 11:56 PM
use this
answer = ifScript();
function ifScript() {
var result = 'yes'; // Default to 'yes'
var mrvsRows = current.variables.low;
var oMrvs = JSON.parse(mrvsRows);
var hasCuba = false;
var hasCanada = false;
var otherCountrySelected = false;
for (var i in oMrvs) {
if (oMrvs[i].low_country === 'Cuba') {
hasCuba = true;
} else if (oMrvs[i].low_country === 'Canada') {
hasCanada = true;
} else {
otherCountrySelected = true;
}
}
if ((hasCuba && hasCanada && !otherCountrySelected) || (hasCuba && !otherCountrySelected) || (hasCanada && !otherCountrySelected)) {
result = 'no';
}
return result;
}
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
03-10-2025 11:56 PM
use this
answer = ifScript();
function ifScript() {
var result = 'yes'; // Default to 'yes'
var mrvsRows = current.variables.low;
var oMrvs = JSON.parse(mrvsRows);
var hasCuba = false;
var hasCanada = false;
var otherCountrySelected = false;
for (var i in oMrvs) {
if (oMrvs[i].low_country === 'Cuba') {
hasCuba = true;
} else if (oMrvs[i].low_country === 'Canada') {
hasCanada = true;
} else {
otherCountrySelected = true;
}
}
if ((hasCuba && hasCanada && !otherCountrySelected) || (hasCuba && !otherCountrySelected) || (hasCanada && !otherCountrySelected)) {
result = 'no';
}
return result;
}
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
03-11-2025 01:04 AM
Thank you Ankur!!!! It is working