Consider the following scenario, you want to send out an email whenever the Owner Group field is changed on a workorder to everyone in the new owner group.
One option is to use MXServer.sendEMail with some hardcoded content or with just a few lines without any kind of formatting.
Better option is to design a Commtemplate and send out a very well formatted email with dynamic content.
There are just a few additional steps in code if you want to do that.
Step 1: Get the CommTemplate Mbo from MXserver
MboSetRemote commSetRemote = getMboSet(“$anylogicalnae”, “COMMTEMPLATE”, ” templateid=’YOUR_TEMPLATE’ “);
Step 2: Get the content:
if(commTemplateRemote.count() > 0)
CommTemplate commRemote = (CommTemplate)commTemplateRemote.getMbo(0);
// mboRemote should be that object whose content wil be replaced in commtemplate. So, if your commtemplate sends out workorder information nand you have used :wonum in your template make sure mboRemote is that object whose information will be resolved/replaced
SqlFormat sqf = new SqlFormat(mboRemote, commRemote.getString(“subject”));
//Set IgnoreUnresolved to true if you want to ignore any errors in commtemplate, errors for stuff like if you have used :wonum and it cannot resolve this attribute.
//Resolve Content method below converts template in to the dynamic content, by resolving I mean instead of :wonum it will put the current records wonum.
String subject = sqf.resolveContent();
//Similarly do it for the message cotent
sqf = new SqlFormat(mboRemote, commRemote.getString(“message”));
String message = sqf.resolveContent();
if (message.length() > 0)
message = message + “rn”;
//Once you have resolved From, to everything else send out the email
MXServer.sendEMail(sendTO, null, null, sendFrom,subject, message, sendFrom, null, null);
A good combination can be if you also attach a report of the workorder with this email. For that you can read my post on attaching a birt report dynamically in java code.