# Trying to get actor emails of a task for sending emails

**URL:** <https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214>\
**Category:** Q&A\
**Created:** [17 February 2014 18:44 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214 "2014-02-17T18:44:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_Snyder](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@Eric\_Snyder](https://community.ofelia.com/u/Eric_Snyder)\
**Post date:** [17 February 2014 18:44 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/1 "2014-02-17T18:44:53Z")

</div>

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](http://community.ofelia.com/answers/how-can-i-get-full-user-list-actor-groovy-script) 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&nbsp;to get email addresses because of my poor Groovy skill. I see [in the API documentation here](http://documentation.bonitasoft.com/javadoc/api/6.2/index.html?org/bonitasoft/engine/api/TenantAPIAccessor.html) 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){  
 &nbsp;&nbsp; &nbsp;if(to!="") to+=","&nbsp;&nbsp; &nbsp;  
 &nbsp;&nbsp; &nbsp;to+=AccessorUtil.getIdentityAPI().getUser(user).getEmail()&nbsp;  
 }  
 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?

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [18 February 2014 14:07 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/2 "2014-02-18T14:07:46Z")

</div>

Hi Eric,&nbsp;  
 The Bonita API has changed in version 6.&nbsp;  
 Objects used in V5 are not the same that are used in the V6.&nbsp;  
 For example: The class "AccessorUtil" in the V5 has been replaced by the class "TenantAPIAccessor" in V6.&nbsp;

If you use the groovy script editor embedded in the Bonita Studio, you can use the variable "apiAccessor" provided in the list.&nbsp;

To retrieve the list of candidates to a user task you can use something like this:&nbsp;  
 ProcessAPI processAPI apiAccessor.getProcessAPI = ();&nbsp;  
 List \<User\> listUsers = processAPI.getPossibleUsersOfPendingHumanTask (ActivityInstanceId, 0, Integer.MAX\_VALUE);&nbsp;

To retrieve the user's professional email you can use something like this:&nbsp;  
 ContactData ContactData = identityAPI.getUserContactData (user.getId (), false);&nbsp;

Hope it can help you  
 Karim

---

<div class="post-metadata">

**Author:** ![celine.souchet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/celine.souchet/32/729_2.png) [@celine.souchet](https://community.ofelia.com/u/celine.souchet)\
**Post date:** [20 February 2014 08:43 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/3 "2014-02-20T08:43:48Z")

</div>

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>
> 
> ```

&nbsp;

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;
> 
> &nbsp;
> 
> ```
> <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>

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![Laurent\_DENIS](https://avatars.discourse-cdn.com/v4/letter/l/e9a140/32.png) [@Laurent\_DENIS](https://community.ofelia.com/u/Laurent_DENIS)\
**Post date:** [31 March 2015 13:31 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/4 "2015-03-31T13:31:21Z")

</div>

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( ‘,’ );

---

<div class="post-metadata">

**Author:** ![celine.souchet](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/celine.souchet/32/729_2.png) [@celine.souchet](https://community.ofelia.com/u/celine.souchet)\
**Post date:** [18 February 2014 10:46 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/5 "2014-02-18T10:46:08Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Eric\_Snyder](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@Eric\_Snyder](https://community.ofelia.com/u/Eric_Snyder)\
**Post date:** [19 February 2014 18:20 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/6 "2014-02-19T18:20:40Z")

</div>

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:&nbsp;

> 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?

---

<div class="post-metadata">

**Author:** ![Eric\_Snyder](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@Eric\_Snyder](https://community.ofelia.com/u/Eric_Snyder)\
**Post date:** [19 February 2014 22:54 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/7 "2014-02-19T22:54:29Z")

</div>

Sorry...6.2 API

---

<div class="post-metadata">

**Author:** ![Eric\_Snyder](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@Eric\_Snyder](https://community.ofelia.com/u/Eric_Snyder)\
**Post date:** [20 February 2014 14:47 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/8 "2014-02-20T14:47:10Z")

</div>

I clicked resolved on the wrong answer!!!

The answer by&nbsp;celine.souchet actually resolved this issue.

---

<div class="post-metadata">

**Author:** ![Eric\_Snyder](https://avatars.discourse-cdn.com/v4/letter/e/b77776/32.png) [@Eric\_Snyder](https://community.ofelia.com/u/Eric_Snyder)\
**Post date:** [20 February 2014 15:23 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/9 "2014-02-20T15:23:40Z")

</div>

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>
> 
> ```

&nbsp;

I checked and resolve dependencies is checked in the script.

---

<div class="post-metadata">

**Author:** ![claudio.taragnolini](https://avatars.discourse-cdn.com/v4/letter/c/b9e5f3/32.png) [@claudio.taragnolini](https://community.ofelia.com/u/claudio.taragnolini)\
**Post date:** [19 April 2017 09:37 UTC](https://community.ofelia.com/t/trying-to-get-actor-emails-of-a-task-for-sending-emails/4214/10 "2017-04-19T09:37:33Z")

</div>

this worked for me thanks
