Tag: email

Split text multiple lines in Email body

HI, Below smaple code used to show splited text in email body.

{

SysMailer mailer;
SysEmailParameters parameters;
InteropPermission permission = new InteropPermission(InteropKind::ComInterop);
OWIStoreTable OWIStoreTable;
Notes bodymsg, bodymsghtml;
ListIterator iterator;
List strlist=new List(Types::String);
;
permission.assert();
mailer = new SysMailer();
parameters = SysEmailParameters::find();

if (parameters.SMTPRelayServerName)
{
mailer.SMTPRelayServer(parameters.SMTPRelayServerName,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}
else
{
mailer.SMTPRelayServer(parameters.SMTPServerIPAddress,
parameters.SMTPPortNumber,
parameters.SMTPUserName,
SysEmailParameters::password(),
parameters.NTLM);
}

mailer.fromAddress(‘test@AX.com’);
mailer.tos().appendAddress(‘AAA@gmail.com’);
mailer.subject(‘System Test’);

strlist =strSplit(‘AAA  BBB’,”\n”);

iterator = new ListIterator(strlist);

while(iterator.more())
{
bodymsg += strFmt(“%1<br>”,iterator.value());
iterator.next();
}

bodymsg = strReplace(bodymsg,’\n’,'<br>’);
bodymsg =bodymsg + “\n” + strFmt(“Last order %2 received for this webtore on: %1”, _lastSalesOrder.createdDateTime);

bodymsghtml= strFmtLB(bodymsg);

mailer.htmlBody(bodymsghtml);

mailer.sendMail();
}

Advertisements

Get Email , phone from CustTable or DirPartyTable

 

HI, Sample code to get primary email if not other email based on Party Id.

FieldId primaryFieldId = DirPartyTable::electronicAddressType2primaryFieldId(LogisticsElectronicAddressMethodType::Email);

//Get Primary

select firstonly logisticsElectronicAddress
join dirPartyTable
where logisticsElectronicAddress.Locator != ”
&& logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Email
&& dirPartyTable.(primaryFieldId) == logisticsElectronicAddress.RecId
&& dirPartyTable.RecId == custTable.Party;

salesTable.Email = logisticsElectronicAddress.Locator;
if(!logisticsElectronicAddress.Locator)
{

//Get other email
select firstonly logisticsElectronicAddress
join Party,Location from dirPartyLocation
where logisticsElectronicAddress.Locator != ”
&& logisticsElectronicAddress.type == LogisticsElectronicAddressMethodType::Email
&& dirPartyLocation.Party == custTable.Party
&& logisticsElectronicAddress.Location == dirPartyLocation.Location;

salesTable.Email = logisticsElectronicAddress.Locator;
if(!salesTable.Email)
salesTable.Email = custEmail;
}

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”);
}

}

}
}
}