---
title: "Select users included in two sets intersected with a third one"
canonical: "https://support.appfire.com/space/PSJ/15482236/Select%20users%20included%20in%20two%20sets%20intersected%20with%20a%20third%20one"
format: markdown
---
> Macro (aura-html)


# Problem

You want to perform complex operations on groups retrieved from Jira. For example, you want to select users included in two merged sets intersected with a third one. The sets can be either groups or roles.

# Solution

> ✅ The following solution is applicable to any other complex operation on sets of users.

> ℹ️ The following script is from a real production system.

For the purpose of this solution, use the following SIL™ functions: **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);
```

This script returns the list of users from **branchcity1** and **branchcity2** in the Accounting and Sales departments of a company.