Need to trigger approvals in workflow based on selected values in list collector.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2024 05:38 AM
I have a requirement where I need to trigger approvals based on the values selected in list collector variable on catalog item. I have a list collector variable(selected_country) on catalog item refers to the country table( which contains all other countries and one option as GLOBAL also).
Then I have one table approval_users where we have two column (approver_name & country), for each country there in only one dedicated approver (for example if I have 100 countries in country table then there are 100 approvers in approval_users table). For Global also there is one approver.
In workflow I have 1st level of approval to group A. Once it is approved I need to trigger next level of approvals depend on List collector (selected_country) variable selection as below:
Case 1: if list collector (selected_country) has 5 countries selected and it does not contain "GLOBAL" ---> Then I need to trigger approvals to all the 5 approvers in approval_users table.
for example: one of the country in list collector is INDIA then approval should be triggered to that one approver from INDIA in approval_users table.
Case 2: if list collector (selected_country) has selected value as "GLOBAL" only one value and it does not contain any other countries ---> Then I need to trigger approval to that one approver is there for global in approval_users table.
Case 3: if list collector (selected_country) has 6 countries selected and also it contains value "GLOBAL" as well ---> Then I need to trigger two levels of approvals here - first approval to all other 5 country's approvers in approval_users table and 2nd approval it should go to GLOBAL approver.
for exmaple: If 3 options are selected in list collector as Global, India and Algeria then 1st level of approval should be triggered approvers in india and algeria and then 2nd level of approval will go to approver in Global.
I need assistance to configure this requirement using workflow.
Thanks in Advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 05:06 AM
Hello @Ramesh_Naidu ,
I implemented above code in my workflow but it's not working. I tried to modify it as per the other approvals are configured for this table, Please find my code below:
var country = current.variables.selected_countries.toString();
var country1 = country.split(",");
var arr = new global.ArrayUtil();
workflow.scratchpad.approval2 = "";
if ((country1.indexOf("3c8520d437461f005b4a04e954990e83")) && (Af_country1.length == "1")) {
//workflow.scratchpad.approval1 = '654b63921bb49414dbe298271d4bcb57';
var abc = new GlideRecord('approval_users');
abc.addQuery('sys_id', '654b63921bb49414dbe298271d4bcb57');
abc.query();
if (abc.next()) {
var finding = new GlideRecord('sys_user');
finding.addQuery('user_name', abc.u_snow_userid);
finding.query();
if (finding.next()) {
workflow.scratchpad.approval1 = finding.sys_id;
}
}
} else if (arr.contains(country1, '3c8520d437461f005b4a04e954990e83')) {
workflow.scratchpad.approval1 = approversList(country1.pop('3c8520d437461f005b4a04e954990e83').toString());
//workflow.scratchpad.approval2 = '654b63921bb49414dbe298271d4bcb57';
var abc = new GlideRecord('approval_users');
abc.addQuery('sys_id', '654b63921bb49414dbe298271d4bcb57');
abc.query();
if (abc.next()) {
var finding = new GlideRecord('sys_user');
finding.addQuery('user_name', abc.u_snow_userid);
finding.query();
if (finding.next()) {
workflow.scratchpad.approval2 = finding.sys_id;
}
}
} else {
workflow.scratchpad.approval1 = approversList(country1.toString());
}
function approversList(u_country_sysid) {
var Ids = [];
var abc = new GlideRecord('approval_users');
abc.addEncodedQuery("u_countryIN"+u_country_sysid);
abc.query();
while (abc.next()) {
var finding = new GlideRecord('sys_user');
finding.addQuery('user_name', abc.u_snow_userid);
finding.query();
while (finding.next()) {
Ids = Ids.push(finding.sys_id);
}
}
return Ids.toString();
}
Actually the thing here is we have other catalog items where"selected_country" is not list collected field, that means we can select only one country at a time. So we have configured approval - user activity for that one approval we are using below code :
var answer = [];
var abc = new GlideRecord('approval_users');
abc.addQuery('u_country',current.variables.selected_countries.getDisplayValue());
abc.query();
if(abc.next())
{
var finding = new GlideRecord('sys_user');
finding.addQuery('user_name',abc.u_snow_userid);
finding.query();
if(finding.next())
{
answer.push(finding.sys_id);
}
}
your code wasn't working here so I tried to modify but even that is also not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 05:23 AM
What is the type of the columns approver_name & country on the approval_user table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2024 05:50 AM
it's normal single liine text fields, but dislpay values are matches with respective tables.
for ex. display value of approver_name is same as u_name in sys_user table, Similarly dislpay value of country filed on approver_user table is same as u_country in country table.
we are fetching it from SNOW_user_id field, that's unique and common field in both the tables -> approval_users & sys_user.