I have look all over the forum and have found various answers but none of them work. Possible they are all for version 5.x?
I did fond this post that got closer. It ends up getting a list of users in the form of ActorMember. What I need to their email addresses. I cannot figure out how to get email addresses because of my poor Groovy skill. I see in the API documentation here that ActorMember has four methods. I can get the member ID but I don't know what to do with it.
I also found an old extension that is a jar but I am not sure how to use it.
I also found an old 5.x example process with this script:
import org.ow2.bonita.util.AccessorUtil
def candidates = AccessorUtil.getQueryRuntimeAPI().getTaskCandidates(activityInstance.getUUID())
def to=""
for(user in candidates){
if(to!="") to+=","
to+=AccessorUtil.getIdentityAPI().getUser(user).getEmail()
}
return to
The issue with this one is that line:
import org.ow2.bonita.util.AccessorUtil
Seems like there are a lot of people in the forums that are looking for the same answer.
Is there someone that can help me get one of these running in 6.2.2?
Hi Eric,
The Bonita API has changed in version 6.
Objects used in V5 are not the same that are used in the V6.
For example: The class "AccessorUtil" in the V5 has been replaced by the class "TenantAPIAccessor" in V6.
If you use the groovy script editor embedded in the Bonita Studio, you can use the variable "apiAccessor" provided in the list.
To retrieve the list of candidates to a user task you can use something like this:
ProcessAPI processAPI apiAccessor.getProcessAPI = ();
List <User> listUsers = processAPI.getPossibleUsersOfPendingHumanTask (ActivityInstanceId, 0, Integer.MAX_VALUE);
To retrieve the user's professional email you can use something like this:
ContactData ContactData = identityAPI.getUserContactData (user.getId (), false);
If you want just the professional email of the user assigned to the task, on your task, you need to add a Groovy connector on Finish, and add the following code :
<p>
// Get the users attached to the actor member of the human task<br />
final List <User> users = apiAccessor.processAPI.getPossibleUsersOfPendingHumanTask(activityInstanceId, 0, Integer.MAX_VALUE);</p>
// Get the professional email of the users<br />
final List<String> professionalEmails = new ArrayList<String>(users.size());<br />
for(final User user : users){
<p class="rteindent1">
ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);<br />
professionalEmails.add(contactData.email);</p>
}
<p>
return professionalEmails;</p>
Source for learning API => what i usually do is look at the source code of Bonita. That’s what I did to be able to write a userFilter for multiple user from variable…
Bonita 6.5, I’m using an e-mail connector that gets its e-mail addresses for all possible candidates (not sure the function getPossibleUsersOfPendingHumanTask exists in 6.2)
Thank you for the reply. I was out yesterday so this is the first I have been able to look at this. When I use the code above I am getting errors. When I isolate the code to just:
Hmmm... I am having an issue. When I tested the script on one task it wen well. Now I have copied the email connector to other tasks. Now I get errors:
Feb 20, 2014 9:18:55 AM org.bonitasoft.engine.log.technical.TechnicalLoggerSLF4JImpl log
WARNING: Error while executing connector with id 23
org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Expression getPossibleActors with content: import org.bonitasoft.engine.identity.User;
<p>
import org.bonitasoft.engine.identity.ContactData;</p>
<p>
// Get the users attached to the actor member of the human task</p>
<p>
final List users = apiAccessor.processAPI.getPossibleUsersOfPendingHumanTask(activityInstanceId, 0, Integer.MAX_VALUE);</p>
<p>
// Get the professional email of the users</p>
<p>
final List professionalEmails = new ArrayList(users.size());</p>
<p>
final String out = "";</p>
<p>
for(final User user : users){</p>
<p>
ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);</p>
<p>
professionalEmails.add(contactData.email);</p>
<p>
out += contactData.email + ",";</p>
<p>
}</p>
<p>
out = out.substring(0, out.length()-1);</p>
<p>
return out; depends on apiAccessor is neither defined in the script nor in dependencies<br />
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:103)<br />
at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:98)<br />
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:150)<br />
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:109)<br />
at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:72)<br />
at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.evaluateInputParameters(ConnectorServiceImpl.java:326)<br />
at org.bonitasoft.engine.connector.ConnectorServiceDecorator.evaluateInputParameters(ConnectorServiceDecorator.java:105)<br />
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:183)<br />
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:147)<br />
at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:207)<br />
at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:119)<br />
at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:72)<br />
at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56)<br />
at org.bonitasoft.engine.work.SequenceRunnableExecutor.innerRun(SequenceRunnableExecutor.java:45)<br />
at org.bonitasoft.engine.work.BonitaRunnable.run(BonitaRunnable.java:35)<br />
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)<br />
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)<br />
at java.util.concurrent.FutureTask.run(Unknown Source)<br />
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)<br />
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)<br />
at java.lang.Thread.run(Unknown Source)<br />
Caused by: groovy.lang.MissingPropertyException: No such property: apiAccessor for class: Script29<br />
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)<br />
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)<br />
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)<br />
at Script29.run(Script29.groovy:7)<br />
at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:97)<br />
... 20 more</p>
I checked and resolve dependencies is checked in the script.
Bonitasoft empowers development teams with Bonita, the open-source and extensible platform to solve the most demanding process automation use cases. The Bonita platform accelerates delivery of complex applications with clear separation between capabilities for visual programming and for coding. Bonita integrates with existing solutions, orchestrates heterogeneous systems, and provides deep visibility into processes across the organization.