Approval Group Workflow Activity Script

Raksha6
Kilo Contributor

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
}

1 ACCEPTED SOLUTION

dvp
Mega Sage
Mega Sage

 

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());
}

View solution in original post

8 REPLIES 8

Raksha6
Kilo Contributor

Thanks for the response dvp. Our group table doesn't have a relationship to the country field, but you're script was helpful.

Raksha6
Kilo Contributor

So there's no other option if the country field isn't related to the group table?

If it is not related you can't do it in a dynamic way.

The other option can be save the list of groups and country association  in a system property as a object and use that in the approval

 

Example

[{'Argentina':'63f8e7f74f01a780627b9efd0210c7fa'}, {'Brazil':'f29eeffb4f01a780627b9efd0210c766'}]

 

Using the system property you can easily add or remove the approvals

Hey

Any update on this?

If one of the responses provided above answered your question, please mark the response as correct so that others in the future can find it quickly and that it gets removed from the unanswered list.