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

1
0
-1

Hello,

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.search.SearchOptionsBuilder
import org.bonitasoft.engine.search.SearchResult

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()){
reviewerList.add(user.getId())
}
return reviewerList;

The result value is like :

  "value": [
    513,
    521
  ],

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(UserFilterServiceImpl.java:131)
at org.bonitasoft.engine.userfilter.UserFilterServiceDecorator.executeFilter(UserFilterServiceDecorator.java:68)
at org.bonitasoft.engine.execution.StateBehaviors.mapUsingUserFilters(StateBehaviors.java:315)
at org.bonitasoft.engine.execution.StateBehaviors.mapActors(StateBehaviors.java:287)
... 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(ReturnTypeChecker.java:53)
at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:94)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:213)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:120)
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:83)
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilterInClassloader(UserFilterServiceImpl.java:206)
at org.bonitasoft.engine.core.filter.impl.UserFilterServiceImpl.executeFilter(UserFilterServiceImpl.java:116)
... 24 more

I do not get the reason why.

Any help would be appreciated .

Thanks in advanced.

Comments

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

1
+1
-1
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:

https://community.bonitasoft.com/project/actor-filter-user-list

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

Comments

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 userList-impl-0.00.zip. 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 userList-impl-0.00.zip 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.

Notifications