Send a notification email to candidates of a task
Hi, i hope that u will able to help me because i am getting crazy.
I found in order how to send "dynamic" notification.
I found lot of thread and also example but refers to previous version of BonitaSoft and does not work in the latest version.
Could you please say how i should update the groovy script discussed here http://community.bonitasoft.com/send-notification-email-candidates-task
for the latest version of BonitaSoft?
So thanks..
I just need of the "To" script, i edited your code removing one grph from line 20 and importing ContactData, but i am still getting error...it's a nutshell!
import org.bonitasoft.engine.identity.ContactData;
def theUser = apiAccessor.getIdentityAPI().getUserByUserName(bonUser.toLowerCase());
if(theUser!=null){
// logger.severe("contact found");
// To have professional email
ContactData professionalData = identityAPI.getUserContactData(theUser.getId(), false);
String professionalEmail = professionalData.getEmail();
if (professionalEmail != null && !professionalEmail.isEmpty()) {
// logger.severe("professionalEmail: "+professionalEmail);
toEmails = professionalEmail;
// logger.severe(toEmails);
}
else{
// logger.severe("contact NOT found");
return "contact NOT found";
}
}
return toEmails;
Comments
so you're getting an error, it was an example.
You have to fix the code,
Have you looked at what the error is?
Have you looked at the logs?
Have you got a variable called bonUser?
Have you assigned it a user name? (wlater.bates for example)
OK here is the full code...
import java.util.logging.Logger;
import java.lang.StringBuilder;
import org.bonitasoft.engine.api.IdentityAPI;
import org.bonitasoft.engine.identity.ContactData;
int dI = 0;
boolean debug = true;
StringBuilder logWrite = new StringBuilder();
Logger logger = Logger.getLogger("org.bonitasoft");
ProcessRuntimeAPI processRuntimeAPI = apiAccessor.getProcessAPI();
logWrite.append("\n\n");
//set the name of the routine
logWrite.append("Process Name: "+ processRuntimeAPI.getProcessInstance(processInstanceId).getName());
logWrite.append("\n\t" + dI++ + "Trace Start");
//TODO - Code goes in here - START
String bonUser = "walter.bates";
String toEmails = "";
def identityAPI = apiAccessor.getIdentityAPI();
def theUser = apiAccessor.getIdentityAPI().getUserByUserName(bonUser.toLowerCase());
if(theUser!=null){
logWrite.append("\n\t" + dI++ + "contact found");
// To have professional email
ContactData professionalData = identityAPI.getUserContactData(theUser.getId(), false);
String professionalEmail = professionalData.getEmail();
if (professionalEmail != null && !professionalEmail.isEmpty()) {
logWrite.append("\n\t" + dI++ + "professionalEmail: "+professionalEmail);
toEmails = professionalEmail;
logWrite.append("\n\t" + dI++ + toEmails);
}
else{
logWrite.append("\n\t" + dI++ + "contact NOT found");
return "contact NOT found";
}
}
logWrite.append("\n\t" + dI++ + "Trace End");
logWrite.append("\n\n");
if(debug){logger.severe(logWrite.toString())}
return toEmails;
and here is the output in the log
0Trace Start
1contact found
2professionalEmail: walter.bates@acme.com
3walter.bates@acme.com
4Trace End
regards
Seán
Do you have a user called Walter Bates?
What's his username?
It's hard coded so choose a name that exists...
The following is an example from what we use. It does work (7.4.3) but you will have to modify it to work for your circumstances.
Using the Email Connector:
From Script (Groovy):
To Script (Groovy) (if you have the username in variable bonUser):
if(theUser!=null){
// logger.severe("contact found");
// To have professional email
ContactData professionalData = identityAPI.getUserContactData(theUser.getId(), false);
String professionalEmail = professionalData.getEmail();
if (professionalEmail != null && !professionalEmail.isEmpty()) {
// logger.severe("professionalEmail: "+professionalEmail);
toEmails = professionalEmail;
// logger.severe(toEmails);
}
else{
// logger.severe("contact NOT found");
return "contact NOT found";
}
}
}
return toEmails;
Subject Script (Groovy):
Message Script (Groovy):
allNotAutoStarted+"<br/><br/>"+
temp1[1].toString()+"<br/>";
return tbl;
regards
Seán
PS: As this reply answers your question, please mark as resolved.
Comments
Good Day,
This works if there is only 1 candidate for the task? What if we have 2 or more candidates for the task? For example the task will be assigned to a role "SDesk", and there are 3 users assigned with the role "SDesk".
Thank you.
- Alfred Ayson
Hi There, but did u tried the above code? it is working? i am getting issue..
Hi Sean,
No worries. Was not really expecting to receive code snippets? Just wanted to bounce some ideas on the scenarios that might come across when implementing the requirement above.
Thanks and Best Regards
Comments
The Bootcamp that happened on 27th-March-2017 shows how to send an email to either the persons manager or the person (it shows one or the other, and from that you can figure easily how to do the other one).
Dunno when they'll get the video of the Bootcamp/webinar online. There's a PDF of the instructions too, which make it as simple as following a paragraph of very clear instructions to link an SMTP connector to a process.
The previous bootcamp might have it too (hopefully still compatible with the latest version).
Do u know where i can find the pdf? thanks
I've pushed it onto Google Drive for you:
Link to PDF
Chapter 5 shows the steps we went through to send an email as part of a process task.