Alert/notify by mail users in a group

Hi! We are going to start using bonita and alerting/notifying that you have a task pending is a must, i had read many other posts but i haven't find a solution,
I would like to send a mail to everyone in a group. i was thinking to do a script to generate coma separated mails but i don't really know how to do it. can you help me? Thanks in advance!

 

Hi.

I am assuming that you're using Bonita BPM 6.

I am adding a simple script whose scope is create a string with comma separated mail address for all users belonged to "/acme/hr" group.

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

Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath("/acme/hr");
List<User> usersInGroup=apiAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC);
StringBuilder sb=new StringBuilder();
for (User user:usersInGroup){
    //get professional contact data
    ContactData contactData = apiAccessor.getIdentityAPI().getUserContactData(user.getId(), false);
    if (contactData!=null && contactData.getEmail()!=null && !contactData.getEmail().isEmpty()){
        sb.append(contactData.getEmail()).append(",");
    }
}
return sb.toString();

You can add a mail connector triggered at start time of the human task,

Let me know if it is clear and if it solve your problem

Ciao,

Domenico.

Try puting the script in a textbox so you can see the result… i didn’t had any trouble with the script…
in the script did you substitute the “/acme/hr” with some actual existing group in your organization?

Continue the error…!! I did try this…
I need this code for implement a connector for send email to users of a group.
I have a conector implemented… this is right… but can only a one user email

Hi, It worked for me!

But, stead of take the email, I want the list of userId.

What do I have to change?

Thank you!

Totally solved my problem, Thanks so much!!!

I need help …!!! for this Script… I implemented in my project…

I have this error:

"java.lang.reflect.InvocationTargetException
org.bonitasoft.engine.bpm.connector.ConnectorExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: groovy.lang.MissingMethodException: No signature of method: static org.bonitasoft.engine.api.APIAccessor.getIdentityAPI() is applicable for argument types: () values:
"

Thanks…!!

Hi Poltowers.
It seems to me that you have made some mistake in the code getting IdentityAPI. Could you attach here the code you’re using?
Ill give a look.
Ciao

Thanks for answer… believe is a problem serialization, but no I sure.

Code:

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 org.bonitasoft.engine.api.APIAccessor;
import org.bonitasoft.engine.api.IdentityAPI;

Group groupSelected=APIAccessor.getIdentityAPI().getGroupByPath(“/utpl/directivo”);
List usersInGroup=APIAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC);
StringBuilder sb=new StringBuilder();
for (User user:usersInGroup){
//get professional contact data
ContactData contactData = APIAccessor.getIdentityAPI().getUserContactData(user.getId(), false);
if (contactData!=null && contactData.getEmail()!=null && !contactData.getEmail().isEmpty()){
sb.append(contactData.getEmail()).append(“,”);
}
}

return sb.toString();

Thanks…

Hi domenico,
i would also like to use your solution,
but my Problem is, I already have the GroupId as a String and would like to use it instead of get GroupByPath.
Can you give me a solution?
Thx

It is not working.

In line 7 there is a “}” remaining.
I created the variable ‘listeUserId’ - StringBuilder listeUserId =new StringBuilder();

Any idea?

Tks

Hi.

Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath(“/acme/hr”);
List usersInGroup=apiAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC);
List listUserId = new ArrayList();
for (User user:usersInGroup){
listUserId.add(user.getId());
}
return listUserId;

EDIT : remove ‘}’ on line 7.

I try it (without the remaining ‘{’ ) and it works for me.