- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 05:28 AM
Can anyone explain how to use list collector values in if condition in workflow for more than one selection. If I select one country from core_country table it's working fine but while selecting two or three countries based on blocked true or false values than it's going to no.
Thank You
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 04:15 AM - edited 09-20-2024 04:29 AM
Since a List Collector stores a comma-separated string of sys_ids, your gr1.AddQuery is always false when there is more than one record. To start off with the script revisions, a Catalog Item workflow typically runs on the sc_req_item table, and you can use current.field_name or current.variables.var_name to access fields on the sc_req_item record, or variables in the Catalog Item, so you shouldn't ever need to do a GlideRecord to retrieve the current RITM record. It's a good practice to initialize variables when you declare them, so I've added that as well for blockedcountry. To get the List Collector value to work with the core_country GlideRecord you need to use sys_id IN the list collector value, not =. I'm guessing you u_blocked_contry is a true/false field you've added to the core_country table, so the rest of the script accommodates that for the potentially multiple country records returned.
answer = ifScript();
function ifScript() {
var blockedcountry = false;
//gs.log('Testing Country New'+ blockedcountry);
var gr1 = new GlideRecord('core_country');
gr1.addQuery('sys_id', 'IN', current.variables.select_which_country_ies_you_will_be_visiting);
gr1.query();
while (gr1.next()) {
if (gr1.u_blocked_country) {
blockedcountry = gr1.u_blocked_country; //only set the script variable to true if the field on this country table is true
break; //no need to continue if one is found
}
}
if (!blockedcontry) {
//gs.log('No blocked countries', blockedcontry);
return 'yes';
} else {
//gs.log('one or more blocked countries', blockedcontry);
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 06:22 AM
A List Collector variable stores the value as a comma-separated list of sys_ids for records on the List table. So in an if statement you could use something like
if (current.variables.list_collector_name.indexOf('a sys_id') > -1) {
indexOf returns the position of the string. If it is not found, it returns -1, so this line means - if one of the selected records on a List Collector is a specific record,...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 01:00 AM
Hi Brad I have written below codes and when i select two country name than it's always going to no condition but when i select single country name based on blocked country column true false its working fine but issue is when selecting more than one country than its always going to no..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 04:15 AM - edited 09-20-2024 04:29 AM
Since a List Collector stores a comma-separated string of sys_ids, your gr1.AddQuery is always false when there is more than one record. To start off with the script revisions, a Catalog Item workflow typically runs on the sc_req_item table, and you can use current.field_name or current.variables.var_name to access fields on the sc_req_item record, or variables in the Catalog Item, so you shouldn't ever need to do a GlideRecord to retrieve the current RITM record. It's a good practice to initialize variables when you declare them, so I've added that as well for blockedcountry. To get the List Collector value to work with the core_country GlideRecord you need to use sys_id IN the list collector value, not =. I'm guessing you u_blocked_contry is a true/false field you've added to the core_country table, so the rest of the script accommodates that for the potentially multiple country records returned.
answer = ifScript();
function ifScript() {
var blockedcountry = false;
//gs.log('Testing Country New'+ blockedcountry);
var gr1 = new GlideRecord('core_country');
gr1.addQuery('sys_id', 'IN', current.variables.select_which_country_ies_you_will_be_visiting);
gr1.query();
while (gr1.next()) {
if (gr1.u_blocked_country) {
blockedcountry = gr1.u_blocked_country; //only set the script variable to true if the field on this country table is true
break; //no need to continue if one is found
}
}
if (!blockedcontry) {
//gs.log('No blocked countries', blockedcontry);
return 'yes';
} else {
//gs.log('one or more blocked countries', blockedcontry);
return 'no';
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2024 01:40 AM - edited 09-20-2024 01:42 AM
var ritm= new GlideRecord('sc_req_item');
if(ritm.get(current.sys_id.toString());
var x = ritm.variables.select_which_country_ies_you_will_be_visiting;
x=x.toString().split(',');
var flag = false;
for (var i = 0; i < x.length; i++) {
var gr = new GlideRecord('core_country');
if (gr.get(x[i])) {
if (gr.u_blocked_country== true) {
flag = true;
break;
}
}
answer = flag;