# Create an exclusive gateway according group

**URL:** <https://community.ofelia.com/t/create-an-exclusive-gateway-according-group/5969>\
**Category:** Q&A\
**Created:** [25 May 2015 12:33 UTC](https://community.ofelia.com/t/create-an-exclusive-gateway-according-group/5969 "2015-05-25T12:33:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hh.molina](https://avatars.discourse-cdn.com/v4/letter/h/f17d59/32.png) [@hh.molina](https://community.ofelia.com/u/hh.molina)\
**Post date:** [25 May 2015 12:33 UTC](https://community.ofelia.com/t/create-an-exclusive-gateway-according-group/5969/1 "2015-05-25T12:33:46Z")

</div>

Hi,

I need to create an exclusive gateway according group, i.e,  
if (the user belong to “production group”) ==\> get an specific way  
else ==\> just get the default way.

I don’t know how to get an attribute from the active user neither to take it and use it as a condition in a gateway.

Can someone help me please?

---

<div class="post-metadata">

**Author:** ![yannick.lombardi](https://avatars.discourse-cdn.com/v4/letter/y/8e8cbc/32.png) [@yannick.lombardi](https://community.ofelia.com/u/yannick.lombardi)\
**Post date:** [26 May 2015 07:10 UTC](https://community.ofelia.com/t/create-an-exclusive-gateway-according-group/5969/2 "2015-05-26T07:10:53Z")

</div>

Hi.

I did this in a process to use the role of a user in a gateway.

First, I get the initiator id with this code in the Operations tab of a task :  
  
return apiAccessor.getProcessAPI().getProcessInstance(processInstanceId).getStartedBy();

After that, I place my gateway. And for each flow, I use this code as condition :  
(I change the role name for each flow)

`
import org.bonitasoft.engine.identity.Role;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.UserCriterion;
Role role = apiAccessor.getIdentityAPI().getRoleByName(“My role”);
int nb = (int) apiAccessor.getIdentityAPI().getNumberOfUsersInRole(role.getId());
List list = apiAccessor.getIdentityAPI().getUsersInRole(role.getId(), 0, nb, UserCriterion.USER_NAME_ASC);
User initiator = apiAccessor.getIdentityAPI().getUser(initiatorId);
`

`if (list.contains(initiator)) return true;
return false;
`

You can do the same for groups by replacing the role by a group.

---

<div class="post-metadata">

**Author:** ![hh.molina](https://avatars.discourse-cdn.com/v4/letter/h/f17d59/32.png) [@hh.molina](https://community.ofelia.com/u/hh.molina)\
**Post date:** [26 May 2015 11:47 UTC](https://community.ofelia.com/t/create-an-exclusive-gateway-according-group/5969/3 "2015-05-26T11:47:45Z")

</div>

Thank you so much, my solution was:

import org.bonitasoft.engine.identity.UserMembership;  
import org.bonitasoft.engine.identity.UserMembershipCriterion;

Boolean flag = false;

List listMemberships = apiAccessor.getIdentityAPI().getUserMemberships(BonitaUsers.getUser(apiAccessor,taskAssigneeId).getId(), 0, 100, UserMembershipCriterion.ASSIGNED\_DATE\_ASC);  
List listGroups = new ArrayList();  
for (UserMembership userMembership : listMemberships){

if(userMembership.getGroupName().equals(“Topografia”) || userMembership.getGroupName().equals(“Obra”) || userMembership.getGroupName().equals(“Presupuestos”)){  
flag=true;  
}  
}  
return flag;
