How to save the output of an actor filter into a variable?
Hello,
I have a process with a lane on which I have an actor Validator
I have configured an actor filter on this lane.
I need to know who are the users that are associated to the lane because I need to send a notification to them.
In my process I need to send the notification in a service task and then after a while I have a human task.
1 answer
Hi, you can execute the actor filter on a service task prior to the lane tasks but it means that:
- The actor filter do not depend on execution context
- The actor filter input is the same between all tasks
- The actor filter implementation will be coupled with the definition
Then you can use a groovy connector on a service task like this:
import org.bonitasoft.actorfilter.identity.UserManagerActorFilter
import org.bonitasoft.engine.connector.EngineExecutionContext
// Instantiate the actor filter
def filter = new UserManagerActorFilter()
// Configure the execution context
filter.setAPIAccessor(apiAccessor)
def context = new EngineExecutionContext()
context.activityInstanceId = activityInstanceId
context.processDefinitionId = processDefinitionId
context.processInstanceId = processInstanceId
context.rootProcessInstanceId = rootProcessInstanceId
filter.setExecutionContext(context)
def processInitiatorId = apiAccessor.processAPI.getProcessInstance(processInstanceId).getStartedBy()
// WARNING: Input parameter must match the one used later in the process
filter.setInputParameters([userId:processInitiatorId])
// Execute it
filter.filter("Employee")
import org.bonitasoft.engine.connector.EngineExecutionContext
// Instantiate the actor filter
def filter = new UserManagerActorFilter()
// Configure the execution context
filter.setAPIAccessor(apiAccessor)
def context = new EngineExecutionContext()
context.activityInstanceId = activityInstanceId
context.processDefinitionId = processDefinitionId
context.processInstanceId = processInstanceId
context.rootProcessInstanceId = rootProcessInstanceId
filter.setExecutionContext(context)
def processInitiatorId = apiAccessor.processAPI.getProcessInstance(processInstanceId).getStartedBy()
// WARNING: Input parameter must match the one used later in the process
filter.setInputParameters([userId:processInitiatorId])
// Execute it
filter.filter("Employee")
Obviously you should replace the UserManagerActorFilter
with the implementation you want to use anf the Employee
actor name with your Lane actor.
HTH
Romain
Comments
I use something like this.
import org.bonitasoft.engine.identity.ContactData;
import org.bonitasoft.engine.identity.Group;
import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.UserCriterion;
import com.bonitasoft.engine.api.IdentityAPI;
import com.bonitasoft.engine.api.ProcessAPI;
IdentityAPI identityapi = apiAccessor.getIdentityAPI();
Group group = identityapi.getGroupByPath("/acme/hr");
List users = identityapi.getUsersInGroup(group.getId(),0,100, UserCriterion.FIRST_NAME_ASC);
String emailList = "";
for(int i=0;i User user = (User)users.get(i);
ContactData contactData = identityapi.getUserContactData(user.getId(),false);
if(i==users.size()-1){
emailList += contactData.getEmail();
}else{
emailList += contactData.getEmail()+"," ;
}
}
return emailList;
Thank you, but I need the users of an actor filter output, not the users of a static group.