How to set multiple actors with specific role with groovy script?
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.
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
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.
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!
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.
Hi,
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
Thanks for the comment,
I created a new question.
https://community.bonitasoft.com/questions-and-answers/how-assign-multip...
Comments
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?
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.