Trying to get actor emails of a task for sending emails

Using Bonita 6.2.2

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?

1 Like

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); 

Hope it can help you
Karim

Hi,

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 :

import org.bonitasoft.engine.identity.ContactData;

<p>
	<br />
	ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,taskAssigneeId);<br />
	return contactData.email;</p>

 

If you want to retieve just the candidates to a user task, you need to add a Groovy connector on Enter, and add the following code :

import org.bonitasoft.engine.identity.User;
import org.bonitasoft.engine.identity.ContactData;

 
<p>
	// Get the users attached to the actor member of the human task<br />
	final List &lt;User&gt; users = apiAccessor.processAPI.getPossibleUsersOfPendingHumanTask(activityInstanceId, 0, Integer.MAX_VALUE);</p>
&nbsp; // Get the professional email of the users<br />
final List&lt;String&gt; professionalEmails = new ArrayList&lt;String&gt;(users.size());<br />
for(final User user : users){
<p class="rteindent1">
	&nbsp;&nbsp; &nbsp;ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);<br />
	&nbsp;&nbsp; &nbsp;professionalEmails.add(contactData.email);</p>
}

<p>
	return professionalEmails;</p>

Best regards,

<p>
	Céline</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)

def emails = []; def users;

def process_api = apiAccessor.getProcessAPI();
def identity_api = apiAccessor.getIdentityAPI();

def human_task_instance = process_api.getHumanTaskInstance(activityInstanceId);

def start_index = 0;
def max_results = 100;

while( users = process_api.getPossibleUsersOfPendingHumanTask(human_task_instance.getId(), start_index, max_results )) {
for( user in users ) {
try {
def pro_user = identity_api.getUserWithProfessionalDetails(user.getId());
def email = pro_user.getContactData().getEmail();
if( email != null ) {
emails.add( email );
}
}
catch( Exception e ) {
}
}
start_index += max_results;
}

emails.unique();
return emails.join( ‘,’ );

Do you want the email of the user assigned to the task, or all users of the actor of the task ?

And, do you want the professional or the personal email ?

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:

ProcessAPI processAPI apiAccessor.getProcessAPI();
return "Hello";

I get: 

ProcessAPI cannot be resolved. It may lead to runtime errors.

<p>
	processAPI cannot be resolved. It may lead to runtime errors.</p>

What may be wrong?

Also, is there a good source for learning how to use 6.6 API?

Sorry...6.2 API

I clicked resolved on the wrong answer!!!

The answer by celine.souchet actually resolved this issue.

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>
	&nbsp;&nbsp; &nbsp;ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);</p>

<p>
	&nbsp;&nbsp; &nbsp;professionalEmails.add(contactData.email);</p>

<p>
	&nbsp;&nbsp; &nbsp;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 />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:103)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.expression.impl.ExpressionServiceImpl.evaluate(ExpressionServiceImpl.java:98)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionWithResolvedDependencies(ExpressionResolverServiceImpl.java:150)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluateExpressionsFlatten(ExpressionResolverServiceImpl.java:109)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.core.expression.control.api.impl.ExpressionResolverServiceImpl.evaluate(ExpressionResolverServiceImpl.java:72)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.evaluateInputParameters(ConnectorServiceImpl.java:326)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.connector.ConnectorServiceDecorator.evaluateInputParameters(ConnectorServiceDecorator.java:105)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:183)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateParameterAndGetConnectorInstance.call(ExecuteConnectorWork.java:147)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.transaction.JTATransactionServiceImpl.executeInTransaction(JTATransactionServiceImpl.java:207)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:119)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:72)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.work.SequenceRunnableExecutor.innerRun(SequenceRunnableExecutor.java:45)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.work.BonitaRunnable.run(BonitaRunnable.java:35)<br />
	&nbsp;&nbsp; &nbsp;at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)<br />
	&nbsp;&nbsp; &nbsp;at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)<br />
	&nbsp;&nbsp; &nbsp;at java.util.concurrent.FutureTask.run(Unknown Source)<br />
	&nbsp;&nbsp; &nbsp;at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)<br />
	&nbsp;&nbsp; &nbsp;at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)<br />
	&nbsp;&nbsp; &nbsp;at java.lang.Thread.run(Unknown Source)<br />
	Caused by: groovy.lang.MissingPropertyException: No such property: apiAccessor for class: Script29<br />
	&nbsp;&nbsp; &nbsp;at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)<br />
	&nbsp;&nbsp; &nbsp;at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)<br />
	&nbsp;&nbsp; &nbsp;at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)<br />
	&nbsp;&nbsp; &nbsp;at Script29.run(Script29.groovy:7)<br />
	&nbsp;&nbsp; &nbsp;at org.bonitasoft.engine.expression.impl.GroovyScriptExpressionExecutorCacheStrategy.evaluate(GroovyScriptExpressionExecutorCacheStrategy.java:97)<br />
	&nbsp;&nbsp; &nbsp;... 20 more</p>

 

I checked and resolve dependencies is checked in the script.

this worked for me thanks