- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 08:59 AM
Hello Community,
I created the below script for an Approval Group workflow activity. The 'country' variable is a Catalog Item reference field for the core_country table. The scripts works as required, however I was wondering if anyone knew an alternate way to have the same functionality without hard coding the group Sys IDs into the script. Thanks
var answer = [];
if (current.variables.country.getDisplayValue() == 'Argentina') {
answer.push('63f8e7f74f01a780627b9efd0210c7fa'); //Sys ID for Argentina approval group
}
else if (current.variables.country.getDisplayValue() == 'Brazil') {
answer.push('f29eeffb4f01a780627b9efd0210c766'); //Sys ID for Brazil approval group
}
else if (current.variables.country.getDisplayValue() == 'Chile') {
answer.push('18d9abb74f01a780627b9efd0210c7b0'); //Sys ID for Chile approval group
}
else if (current.variables.country.getDisplayValue() == 'Colombia') {
answer.push('c9aa6b3b4f01a780627b9efd0210c779'); //Sys ID for Colombia approval group
}
else if (current.variables.country.getDisplayValue() == 'Ecuador') {
answer.push('dc2b277b4f01a780627b9efd0210c7ca'); //Sys ID for Ecuador approval group
}
else if (current.variables.country.getDisplayValue() == 'Panama') {
answer.push('b89bab7b4f01a780627b9efd0210c747'); //Sys ID for Panama approval group
}
else if (current.variables.country.getDisplayValue() == 'Peru') {
answer.push('af1caf7b4f01a780627b9efd0210c777'); //Sys ID for Peru approval group
}
else if (current.variables.country.getDisplayValue() == 'Puerto Rico') {
answer.push('008c67bb4f01a780627b9efd0210c737'); //Sys ID for Puerto Rico approval group
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:46 AM
Is there a country field on group form that relates groups to a country? If yes you can write a script to get the group sysId
Here is the sample script
var answer = [];
var gr = new GlideRecord("sys_user_group");
gr.addQuery("u_country", current.variables.country); //u_country is the field name on group form. You might need to update it
gr.query();
if (gr.next()) {
answer.push(gr.sys_id.toString());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2019 10:18 AM
I think you can use the reference variable to trigger approvals for group. Below code should work.
----------------------*********------------------------
answer = [];
var group = current.variables.group_approval_required.sys_id; //group_approval_required - reference variable. Please change it according to the variable name at your end.
answer.push(group);
---------------------***********--------------------
Please hit correct based on impact of response.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:28 AM
Thanks for the response Nitin. Unfortunately that script didn't work. I'm looking to route the approval to a specific group based on the country selected on the Catalog Item request (i.e. Brazil = Brazil approval group, Chile = Chile approval group, etc). The script I provided does this, however I was wondering if there was an alternate script that can be done without the Sys IDs being hard coded. I've also tried the Switch activity, but decided to go this route since we plan to expand out to more countries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2022 11:10 AM
Thanks this worked perfect for my case! I had an ask for on a task to have 5 reference variables to ask for 5 approvers and I could not get it to work with just
answer = [];
answer.push(current.variables.task_variable_user1);
But when I added your code
answer = [];
var appr1 = current.variables.task_approver_1.sys_id;
answer.push(appr1);
Worked like a charm

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2019 08:46 AM
Is there a country field on group form that relates groups to a country? If yes you can write a script to get the group sysId
Here is the sample script
var answer = [];
var gr = new GlideRecord("sys_user_group");
gr.addQuery("u_country", current.variables.country); //u_country is the field name on group form. You might need to update it
gr.query();
if (gr.next()) {
answer.push(gr.sys_id.toString());
}