# How to send emails to Users of specific Roles

**URL:** <https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424>\
**Category:** Q&A\
**Created:** [21 April 2014 09:25 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424 "2014-04-21T09:25:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![alfred.ayson](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@alfred.ayson](https://community.ofelia.com/u/alfred.ayson)\
**Post date:** [21 April 2014 09:25 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/1 "2014-04-21T09:25:33Z")

</div>

Good day,

I’m trying to use an email connector to send an email to Users included in a specific Role.

I tried using _getPossibleUsersOfPendingHumanTask_ but it only works for Human Tasks with connectors. I need to have a Service Task which sends the email to actors of a specific role.

Can anyone help me on this?

Regards,

Alfred Ayson  
Consultant

---

<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:** [22 April 2014 09:22 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/2 "2014-04-22T09:22:15Z")

</div>

Hi,

You can use the new implementation of getPossibleUsersOfHumanTaskong processDefinitionId, String humanTaskName, int startIndex, int maxResults) since 6.1 to get the paginated list of possible users of a user task.  
Then for each user you can call identityAPI.getUserWithProfessionalDetails(userId) to get each email address.  
You can achieve this goal in a groovy script.

HTH,

---

<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:** [21 April 2014 22:21 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/3 "2014-04-21T22:21:33Z")

</div>

Hi,  
Please note that there is no actor associate with service task. It always executed by the system. Not sure what you are trying to do here but you can use [operations](http://documentation.bonitasoft.com/operations) previous task to get pending users and save it as variable. Your email connector can use that variable.

Let me know how it goes…  
Ronak

---

<div class="post-metadata">

**Author:** ![alfred.ayson](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@alfred.ayson](https://community.ofelia.com/u/alfred.ayson)\
**Post date:** [22 April 2014 01:39 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/4 "2014-04-22T01:39:05Z")

</div>

Hi ronak,

Maybe i was not clear in my description. What I would want to do is to send an email to the actors of a particular swimlane to inform them that they need to login and perform the task assigned to them.

I would want to get the email addresses of the actors/users in the swimlane especially if there are more than one .

Thank you.

---

<div class="post-metadata">

**Author:** ![paul33](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@paul33](https://community.ofelia.com/u/paul33)\
**Post date:** [22 April 2014 07:51 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/5 "2014-04-22T07:51:17Z")

</div>

Hi,  
I’ve asked the same question on : [http://community.ofelia.com/answers/get-lane-actor-groovy](http://community.ofelia.com/answers/get-lane-actor-groovy)  
but I still don’t know how to do it. So I am interested if you find an answer !

---

<div class="post-metadata">

**Author:** ![paul33](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@paul33](https://community.ofelia.com/u/paul33)\
**Post date:** [22 April 2014 10:07 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/6 "2014-04-22T10:07:12Z")

</div>

Hi,  
Thanks for the help (even if it wasn’t for me in the first place 🙂 ).  
I tried on Bonita Studio 6.2.3 : return getPossibleUsersOfHumanTaskong(processDefinitionId,Step2, 0,5); but I get a “depends on Step2 is neither defined in the script nor in dependencies”.  
So how do we call a specific humanTaskName ?  
Regards,

---

<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:** [22 April 2014 10:12 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/7 "2014-04-22T10:12:03Z")

</div>

add quotes around Step2 because in a groovy script step2 is considered as a variable

→ return getPossibleUsersOfHumanTaskong(processDefinitionId,‘Step2’, 0,5);

Regards

---

<div class="post-metadata">

**Author:** ![paul33](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@paul33](https://community.ofelia.com/u/paul33)\
**Post date:** [22 April 2014 11:57 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/8 "2014-04-22T11:57:44Z")

</div>

Thanks again !  
I tried it but now, I have got : “No signature of method: Script1.getPossibleUsersOfHumanTaskong() is applicable for argument types: (java.lang.Long, java.lang.String, java.lang.Integer, java.lang.Integer) values: [9193000046765828276, Step2, 0, 5]”  
Do I miss an import or something else ?  
Regards

---

<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:** [22 April 2014 12:13 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/9 "2014-04-22T12:13:13Z")

</div>

I made a mistake the signature is:

getPossibleUsersOfHumanTask(processDefinitionId,‘Step2’, 0,5);

I let ‘ong’ at the end of the method name

My apologizes,  
Regards,

---

<div class="post-metadata">

**Author:** ![paul33](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@paul33](https://community.ofelia.com/u/paul33)\
**Post date:** [22 April 2014 12:23 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/10 "2014-04-22T12:23:43Z")

</div>

Ok, I thought so as i couldn’t find it in the javadoc … So I already tried  
“return getPossibleUsersOfHumanTask(processDefinitionId,‘Step2’, 0,5);” but it gave me the same warning of “No signature of method”…  
Sorry if that’s something stupid, i’m pretty new to Bonita…

---

<div class="post-metadata">

**Author:** ![alfred.ayson](https://avatars.discourse-cdn.com/v4/letter/a/22d042/32.png) [@alfred.ayson](https://community.ofelia.com/u/alfred.ayson)\
**Post date:** [23 April 2014 01:05 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/11 "2014-04-23T01:05:45Z")

</div>

Here is what I did…I got this part of code also in this forum…I just saved the output into a list variable

import org.bonitasoft.engine.identity.User; import org.bonitasoft.engine.identity.ContactData; import org.bonitasoft.engine.bpm.actor.ActorCriterion;

// Get the users attached to the actor member of the human task  
final List users = apiAccessor.processAPI.getPossibleUsersOfPendingHumanTask(activityInstanceId, 0, Integer.MAX\_VALUE);

// Get the professional email of the users  
final List professionalEmails = new ArrayList(users.size());  
for(final User user : users){

ContactData contactData = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,user.id);  
professionalEmails.add(contactData.email);

}

return professionalEmails;

---

<div class="post-metadata">

**Author:** ![paul33](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@paul33](https://community.ofelia.com/u/paul33)\
**Post date:** [23 April 2014 09:45 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/12 "2014-04-23T09:45:40Z")

</div>

Thanks for the help.  
I did it but it only works on a human task ? didn’t you try it on a service task ?

---

<div class="post-metadata">

**Author:** ![paul33](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@paul33](https://community.ofelia.com/u/paul33)\
**Post date:** [23 April 2014 13:32 UTC](https://community.ofelia.com/t/how-to-send-emails-to-users-of-specific-roles/4424/13 "2014-04-23T13:32:57Z")

</div>

Thanks ! it works! I just changed the method by : getPossibleUsersOfHumanTask(processDefinitionId, “Step3”, 0, Integer.MAX\_VALUE);
