email template in ax 2012

Hi,

Below is the sample code written to send a mail to manager when a leave requested is submitted by employee. The mail alert will to corresponding reporting manager.

public static void main(Args args)
{
LeaveSubmittoWorkflow limitRequestWorkflow;
Mzk_LeaveHistory limitRequest;
Mzk_LeaveMaster leaveMaster;
Mzk_LeaveHistory leaveHisotry;
SysMailer mail;
HcmWorker HcmWorker,hcmworkerHR,hcmmanager,hcmworkerempl;
HcmPositionId position;
HcmPositionRecId parentid;
LogisticsLocationEntity location;
str senderEmail;
str recipientEmail;
str messageText, leavetype;
Name empl, Manager;
str cc, to, body, sub;
DirPerson dirperson;
DirPartyTable partytable,party;
HcmPositionWorkerAssignment HcmPositionWorkerAssignment;

mail = new SysMailer();
limitRequest = args.record();

leavetype = HcmLeaveType::find(limitRequest.LeaveType).description;
select * from hcmworkerempl
where hcmworkerempl.RecId == limitRequest.Worker;
//Employee Data
select firstonly Name from partytable
where partytable.RecId == hcmworkerempl.Person;

empl = partytable.Name;
select * from HcmPositionWorkerAssignment
WHERE HcmPositionWorkerAssignment.Worker == limitRequest.Worker;
//parentid = HcmPositionHierarchy::find(Global::currentWorker()).ParentPosition;
parentid = HcmPosition::getReportsToPosition(HcmPositionWorkerAssignment.Position);
position = hcmposition::find(parentid).PositionId;
HcmWorker = HcmWorker::findByPersonnelNumber(position);
//Manager
select * from hcmmanager
where hcmmanager.PersonnelNumber == position;
HcmWorker = HcmWorker::find(HcmPositionWorkerAssignment::findByPosition(parentid).Worker);
select firstonly Name from party where party.RecId == HcmWorker.Person;
Manager = party.Name;

location = DirParty::primaryElectronicAddressLocation(HcmWorker.Person, LogisticsElectronicAddressMethodType::Email);

if(location)
{
recipientEmail = location.getEmail();
}
senderEmail = ‘ax@wordpress.com’;

if (LeaveSubmittoWorkflow::canSubmit(limitRequest))
{
limitRequestWorkflow = LeaveSubmittoWorkflow::construct();
limitRequestWorkflow.init(args.record(), args.menuItemName(), null,null, args.caller());

if (limitRequestWorkflow.dialogOk())
{
if (limitRequestWorkflow.parmSubmit())
{
limitRequestWorkflow.submit();
}
if (args.record() &&
args.record().TableId == tablenum(Mzk_LeaveHistory))
{

leaveHisotry = args.record();
// info(strFmt(“%1″,leaveHisotry));
ttsBegin;
leaveHisotry.selectForUpdate(true);
leaveHisotry.LeaveStatus = LeaveStatus::Submitted;
leaveHisotry.update();
ttsCommit;
if ((recipientEmail != ”) && (senderEmail != ”))
{

//mail body
sub = strfmt(“Regarding the Leave Request”);
body = “<html><body>”+ strfmt(“Dear %1,”,Manager)+ “<br/><br>”+
strfmt(“Mr/Mrs %1 being employee Id %2 has applied for the %3. Your action is required to approve/reject the request. Please login to Portal and do needful”,empl,hcmworkerempl.TransferEmployeeCode,leavetype) + “<br/><br>”;
body = body + strfmt(“So please go through thr following Details”) + “<br/><br>”;
body = Body + “<html> <body><table border=’1′>”;

body= body+ “<tr><td>” + “Employee code” +”</td>”;
body= body+ “<td>” + strfmt(“%1″,hcmworkerempl.TransferEmployeeCode) +”</td></tr>”;

body= body+ “<tr><td>” + “Employee Name” +”</td>”;
body= body+ “<td>” + strfmt(“%1″,empl) +”</td></tr>”;

body= body + “<tr><td>” + “Manager Code” +”</td>”;
body= body + “<td>” + strfmt(“%1″,hcmmanager.TransferEmployeeCode) +”</td></tr>”;

body= body + “<tr><td>” + “Manager Name ” +”</td>”;
body= body + “<td>” + strfmt(“%1″,Manager) +”</td></tr>”;

body= body + “<tr><td>” + “Leave Type ” +”</td>”;
body= body + “<td>” + strfmt(“%1″,leavetype) +”</td></tr>”;

body= body + “<tr><td>” + “Leave start date ” +”</td>”;
body= body + “<td>” + strfmt(“%1″,limitRequest.StartDate) +”</td></tr>”;

body= body + “<tr><td>” + “Leave End Date ” +”</td>”;
body= body + “<td>” + strfmt(“%1″,limitRequest.EndDate) +”</td></tr>”;

body = body + “<tr><td>” + “No.of WorkingDays ” + “</td>”;
body= body + “<td>” + strfmt(“%1″,limitRequest.NoofWorkingDays) +”</td></tr>”;

 

Body= Body + “</table>”;

Body = Body + strfmt(“<br/><br/>Potal Link:// give link where the manager needs to approve leave”);
Body = Body + strfmt(“<br/><br/><b>Note:This is a system generated email. Please do not reply to this mail.</b> </body></html>”);
mail.quickSend(senderEmail, recipientEmail,sub, Body);
}
else
{
info(“@SYS134424”);
}

}

}
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s