How to set multiple actors with specific role with groovy script?



I created a groovy script in order to get users has a specific role in a specific group.

I set the actor with groovy script

import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.Group;
import org.bonitasoft.engine.identity.GroupCriterion;
import org.bonitasoft.engine.identity.User;

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

IdentityAPI identity = apiAccessor.getIdentityAPI();

long specificRoleId=apiAccessor.identityAPI.getRoleByName("approver").getId();
final SearchOptionsBuilder builder = new SearchOptionsBuilder(0, 100);
builder.filter(UserSearchDescriptor.GROUP_ID, department);
builder.filter(UserSearchDescriptor.ROLE_ID, specificRoleId);

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

The result value is like :

  "value": [

However, I got the error.

Caused by: org.bonitasoft.engine.core.filter.exception.SUserFilterExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: FLOW_NODE_INSTANCE_ID=1400397 | Declared return type class java.lang.Long is not compatible with evaluated type class java.util.ArrayList for expression userId()
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilter(
at org.bonitasoft.engine.userfilter.UserFilterServiceDecorator.executeFilter(
at org.bonitasoft.engine.execution.StateBehaviors.mapUsingUserFilters(
at org.bonitasoft.engine.execution.StateBehaviors.mapActors(
... 21 more
Caused by: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: FLOW_NODE_INSTANCE_ID=1400397 | Declared return type class java.lang.Long is not compatible with evaluated type class java.util.ArrayList for expression userId()
at org.bonitasoft.engine.expression.impl.ReturnTypeChecker.checkReturnType(
at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilterInClassloader(
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilter(
... 24 more

I do not get the reason why.

Any help would be appreciated .

Thanks in advanced.


Submitted by rtumminelli_1394599 on Thu, 03/14/2019 - 21:05

Is this script an Actor Filter?

It looks like a userId of type Long is expected but you're returning an ArrayList.

Are you trying to return a list of users you want to assign a task to?

Submitted by donghee.baik on Thu, 03/14/2019 - 21:11

Thanks for the comment.

Yes the script is inside an actor filter.

I just knew that I set the script in the single user actor.

if I want to set multiple users in side the actoer filter, how can I set the actor in Actors tab?

Thanks in advanced.

1 answer

This one is the BEST answer!

If you simply want to assign an entire Group, Role or Membership to a lane, you can map them to an Actor in the Configuration menu. If you are trying to assign a specific set of individuals in one of those groups, you have to create your own custom Actor Filter Definition and Implementation.

While trying to do this myself, I discovered someone has already created a filter that returns a list of users:

You can simply import that Actor Filter .zip, and it will let you return a list of userIds in your filter script.


Submitted by donghee.baik on Thu, 03/14/2019 - 21:36

Thanks for the comment again.

I am going to try what you recommended. I believe that this is what I exactly want.

I will update the result.

Thanks a lot.

Submitted by rtumminelli_1394599 on Thu, 03/14/2019 - 21:45

Sure. So from the Github page, download the ZIP file. Extract it to a folder and you should see This is the Actor Filter that we want to import to our project. In Bonita Studio, go to the Development tab at the top, select Actor Filters, then select Import. Navigate to the we previously extracted and import it. You should get a popup that shows it successfully imported the filter. Now you should have a new filter option when you go to set an Actor Filter on any Lane.

Submitted by donghee.baik on Fri, 03/15/2019 - 15:52

Thanks for the explanation. I imported the actor filter and set the actor with groovy.

It works perfectly.

I appreciate your help.:)

Thanks a lot!

Submitted by donghee.baik on Mon, 03/18/2019 - 14:13

I faced another issue. The user list works well. However, the task did not assign all users of the returned list. So, once each user selects the task, The message "To fill out the form, you need to take this task. This means you will be the only one able to do it. To make it available to the team again, release it. " comes out.

I need to assign the task for all users of the returned users. Do you have any idea?
Thanks in advanced.

Submitted by delphine.coille... on Tue, 04/02/2019 - 11:38


I see that your question is not directly related to the previous one, could you please copy and paste it in a new question?

Thanks Delphine

Submitted by donghee.baik on Tue, 04/02/2019 - 15:34