Hello, I need to send an email with multiple senders that I get from a database. Try to put as a target variable type List but did not work.
As I can do?
Hi,
I will explain you all steps:
- create a global variable in your pool:
- variable “allUsersEmailSLS” - type “java.list”
In this variable, you store all the users emails from the role “SLS”
- variable “allUsersEmailSLS” - type “java.list”
Scrypt:
import org.bonitasoft.engine.identity.UserCriterion;
import org.bonitasoft.engine.identity.User;
long idRoleSLS = apiAccessor.getIdentityAPI().getRoleByName(“SLS”).getId();
ArrayList listUsersSLS = apiAccessor.identityAPI.getUsersInRole(idRoleSLS, 0, 15, UserCriterion.FIRST_NAME_ASC);
ArrayList listMailSLS = new ArrayList();
for (User uSLS : listUsersSLS) {
String eMailSLS = BonitaUsers.getUserProfessionalContactInfo(apiAccessor,uSLS.getId()).getEmail();
listMailSLS.add(eMailSLS);
}
return listMailSLS;
- Transform the list as a string because in the mail connector, you can’t put a list for the sender and receiver adress.
So, create another variable - type “Text”
Scrypt:
String listStringSLS = “”;
int nbElementsSLS = allUsersEmailSLS.size();
int compteurSLS = 0;
String separateurVirguleSLS = “,”;
String separateurVideSLS = “”;
for (String sSLS : allUsersEmailSLS) {
compteurSLS += 1;
if(compteurSLS == nbElementsSLS){
listStringSLS += sSLS + separateurVideSLS;
}
else {
listStringSLS += sSLS + separateurVirguleSLS;
}
}
return listStringSLS;
The emails that I need are in a mysql since it does not belong to the same role in Bonita
You can’t put a list for the sender in an email connector. You must convert your list to a string. That’s why there is a second part in my first topic.
==> Create a list to collect your emails from your database and convert it and store it to a variable. Put this new variable for the sender.
Can you retrieve the emails from the database to a text field for example?