Alert/notify by mail users in a group

1
0
-1

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!

4 answers

1
+1
-1
This one is the BEST answer!

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;<br />
        import org.bonitasoft.engine.identity.Group;<br />
        import org.bonitasoft.engine.identity.User;<br />
        import org.bonitasoft.engine.identity.UserCriterion;

Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath("/acme/hr");<br />
        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.

Comments

Submitted by efrados on Thu, 02/27/2014 - 13:51

Totally solved my problem, Thanks so much!!!

Submitted by poltowers on Wed, 04/23/2014 - 01:22

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...!!

Submitted by domenico.giordano on Wed, 04/23/2014 - 09:20

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

Submitted by poltowers on Wed, 04/23/2014 - 23:44

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

Submitted by max.schmidt on Thu, 05/04/2017 - 09:13

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

1
0
-1

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

Submitted by emersonaredes on Mon, 08/04/2014 - 15:49

It is not working.

In line 7 there is a "}" remaining. I created the variable 'listeUserId' - StringBuilder listeUserId =new StringBuilder();

Any idea?

Tks

Submitted by yannick.lombardi on Mon, 08/04/2014 - 16:07

Hi.

Group groupSelected=apiAccessor.getIdentityAPI().getGroupByPath("/acme/hr");
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.

Submitted by yannick.lombardi on Mon, 08/04/2014 - 16:10

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

1
0
-1

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

1
0
-1

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?

Notifications