Selecting users member of the reunion of 2 sets intersected with a third one
Problem
Context: complex operations on groups, groups are taken from Jira. The problem is to select users which are members of the reunion of 2 sets intersected with a third one (the sets may be either groups or roles).
You can imagine any other complex operation on sets of users. The following excerpt is from a real production system.
Solution
Use several SIL™ routines: usersInGroups, arrayToSet, arrayUnion, arrayGetElement, arrayIntersect.
//Which employees from branches placed in city1, city2 are working in sales and accountancy field?
string [] branchcity1 = arrayToSet({"branchA", "branchB", "branchC"});
string [] branchcity2 = arrayToSet({"branchD", "branchE"});
string [] employeegroup = arrayToSet({"sales", "accountancy"});
string [] city1users;
for(number i = 0; i < size(branchcity1); i = i + 1) {
city1users = arrayUnion(city1users, usersInGroups(arrayGetElement(branchcity1, i)));
}
string [] city2users;
for(number i = 0; i < size(branchcity2); i = i + 1) {
city2users = arrayUnion(city2users, usersInGroups(arrayGetElement(branchcity2, i)));
}
string [] employees;
for(number i = 0; i < size(employeegroup); i = i + 1) {
employees = arrayUnion(employees, usersInGroups(arrayGetElement(employeegroup, i)));
}
string [] branchusers = arrayToSet(arrayUnion(city1users, city2users));
return arrayIntersect(employees, branchusers);The code above returns the list of users from branchcity1 and branchcity2 working in accountancy and sales departments of a company.
See also
Rolling summation or subtraction between parent and child fields
Use Live Fields to initialise field values for a transition screen