How to set actor filter with group name and role name ?

I would like to get a user list with specific membership.
I created department bdm and stored department name.

I would like to set Actors with specific group users with a specific role.
variable stored selected groups by a user.

Actor filter has a script as follows :
In this code is username.
However, I would like to send group names in variable.

import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.User;
IdentityAPI identity = apiAccessor.getIdentityAPI();
User user = identity.getUserByUserName(group);
return user.getId();

Would you help me to get users list with specific group and role ?

1 Like

Hi,

I think actor and actor filter need a little bit of clarification.

Actor and actor filters are two alternatives to define who can perform a task. Several users might be able to perform one task. In order to avoid concurrent access to execute a task, a user can claim and release a task in the Bonita portal.

Now what is the difference between actor and actor filter:

  • Actor: in the process definition an actor is just a name associate with a lane or directly with a task. In process configuration you will then associate this actor with group(s), role(s), membership(s), user(s) or any combinations of all the previous in order to define who can do the task. Configuration of the actor is only based on organization (users, roles, groups) information. It cannot use process information such as a process business data or information about the user who start the process.
  • Actor filter: first this is really a bad name as it actually does not filter anything. Actor filter is another solution to create a list of users who can do a task. This list of user will be compute by executing an actor filter when the task is reached. An actor filter can have inputs and is executed when the process instance is running. So an actor filter can use information such as process business variable, process instance initiator (the user who start the process)… Actor filter is for example useful if you want to assign a task to the manager of the user who start a process instance. You have a catalog of actor filters available out of the box and you can also create your own one.

In your situation, as you want to associate your task to users only based on roles and groups information, actor option should do the trick.

Let me know if this is not perfectly clear for you.

Regards

import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.UserMembership;
import org.bonitasoft.engine.identity.UserMembershipCriterion;
import org.bonitasoft.engine.identity.UserSearchDescriptor;
import org.bonitasoft.engine.search.SearchOptionsBuilder
import org.bonitasoft.engine.search.SearchResult;

List memberships = apiAccessor.identityAPI.getUserMemberships(userId,0,1,
UserMembershipCriterion.ASSIGNED_DATE_ASC);
Long groupId;
if(memberships!=null && memberships.size()>0) {
groupId = memberships[0].getGroupId()
}

//manager is a example on get role by name change it with your role name
long specificRoleId=apiAccessor.identityAPI.getRoleByName(“manager”).getId();
final SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 100);
builder.filter(UserSearchDescriptor.GROUP_ID, groupId);
builder.filter(UserSearchDescriptor.ROLE_ID, specificRoleId);

final SearchResult userResults = apiAccessor.identityAPI.searchUsers(builder.done());
List reviewerList = new ArrayList();
for(User user:userResults.getResult()){
reviewerList.add(user.getId())

}

return reviewerList

I hope this will help ,

best regards

Thanks for your help.
It helps a lot to me.
Then, I realized that I need to change the question.

Is it possible to get a manager’s id from groupName?
From group name, is it possible to get a manager’s id from each group?

Thanks for your help. I thought I was not clear about the concept. This is really helpful to me.
I realized that I need to change the question.
For example, I would like to change the question.

Is it possible to get a manager’s id from grouplist?
From group name, is it possible to get a manager’s id from each group?

import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.User;
IdentityAPI identity = apiAccessor.getIdentityAPI();
User user = identity.getUserByUserName(groups);
return user.getId();

For your use case maybe you can configure the actor to get all users with the role “manager”.

If it is not what you are looking for maybe can you provide a little bit more details about your use case?

Thanks for the comment.
I would like to explain my situation.

I am modifying a task done by the other person.
In UI form, a user selects groups, put request and upload files, then submit the task.
The selected group returned group names, then, I stored them into groups.
The original code sends the userName by pure JSON.

I would like to store manager’s ids and send or set Actor as a manager from selected groups.

I need to get manager’s name in UI form or need to get the manager’s list in actor groovy script as I write the code.

I hope this works for understanding.

Thanks in advance,

If I understand correctly in a task a user will select groups of organization managed by Bonita.

After this first task you have a second task that should be performed by one (or maybe performed by all) manager of selected groups.

Is that correct?

Yes. it is correct.
In the first task, a user selects one or many groups. The return value is groupName
The second task should be taken by managers of selected groups.

Thanks for your help.

I can solve this using by database connector and retrieve the group name and manager name in the task,
However, I would like to solve the issue with actor filter configuration.

In Actor filter of the second task, set the users with a groovy script as managers of groups.

Is it the right way to approach the issue?
Thanks a lot.

I create an example of custom connector that I think do what you are looking for. An example of process is available as well. You can get it from GitHub: https://github.com/Bonitasoft-Community/custom-actor-filter-group-manager

Thanks for providing the example.
However, I could not download the latest release bos file from the github.
Would you update the final version of the release, please?

Thanks in advance.

On GitHub if you switched to the “release” tab (between “branch” and “contributors” right above the list of files and the buttons such as “clone or download”) you get the following page: https://github.com/Bonitasoft-Community/custom-actor-filter-group-manager/releases

On this release page, if you select one specific release (such as 0.0.1) you get a page dedicated to this specific version. E.g. https://github.com/Bonitasoft-Community/custom-actor-filter-group-manager/releases/tag/0.0.1

On a specific release page you always have two files (zip and tar.gz) that includes source code. Optionally you have additional files.

For my example on https://github.com/Bonitasoft-Community/custom-actor-filter-group-manager/releases/tag/0.0.1 you can find a file named project_20190211_1624.bos that can be downloaded and import in the Studio.

Here is a direct link to download the file: https://github.com/Bonitasoft-Community/custom-actor-filter-group-manager/releases/download/0.0.1/project_20190211_1624.bos

Does this expire?