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.Group;<br />
import org.bonitasoft.engine.identity.User;<br />
import org.bonitasoft.engine.identity.UserCriterion;
List<User> usersInGroup=apiAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC);<br />
StringBuilder sb=new StringBuilder();<br />
for (User user:usersInGroup){<br />
//get professional contact data<br />
ContactData contactData = apiAccessor.getIdentityAPI().getUserContactData(user.getId(), false);<br />
if (contactData!=null && contactData.getEmail()!=null && !contactData.getEmail().isEmpty()){<br />
sb.append(contactData.getEmail()).append(",");<br />
}<br />
}<br />
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.
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!
Comments
Hi.
List<User> usersInGroup=apiAccessor.getIdentityAPI().getUsersInGroup(groupSelected.getId(), 0, 100, UserCriterion.FIRST_NAME_ASC);
List<Long> listUserId = new ArrayList<Long>();
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.
Comments
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