Class:
class SendMailUsingOutlook extends
RunBase
{
Counter progressCounter;
HRMApplicationEmailTemplate hrmApplicationEmailTemplate;
DNGRSUnitHandover dngrsUnitHandover;
DNGRSWorkCompletion dngrsWorkCompletion;
}
Main method:
static void
main(Args args)
{
DNGRSUnitHandover dngrsUnitHandover;
DNGRSWorkCompletion dngrsWorkCompletion;
FreeTxt
bodyText,bodytext2,Fullbody,bodytext3;
SendMailUsingOutlook SendMailUsingOutlook =
new SendMailUsingOutlook();
if
(!args)
{
throw
error("@SYS25407");
}
dngrsUnitHandover = args.record();
SendMailUsingOutlook.parmDNGRSUnitHandover(dngrsUnitHandover);
SendMailUsingOutlook.run();
}
Parm method
for getting Args:
public DNGRSUnitHandover
parmDNGRSUnitHandover(DNGRSUnitHandover _DNGRSUnitHandover = dngrsUnitHandover)
{
dngrsUnitHandover = _DNGRSUnitHandover;
return
dngrsUnitHandover;
}
Progress Update:
void progressUpdate(str text)
{
;
progressCounter++;
progress.setCount(progressCounter);
progress.setText(text);
}
Run:
Public void run ()
{
FreeTxt
bodyText,bodytext2,Fullbody,bodytext3;
DNGRESAgreementUnitSpecification dngresAgreementUnitSpecification;
DNGRSWorkCompletionChangeOrderSpec dngrsWorkCompletionChangeOrderSpec;
DNGRSDocumentList DNGRSDocumentList;
DNGRSWorkLineDetails DNGRSWorkLineDetails;
DNGRSInspectionDetails DNGRSInspectionDetails;
DNGRSSpecificationTable DNGRSSpecificationTable;
;
bodyText += "<TABLE
border=1 style=width:1000px cellspacing=0 cellpadding=0><font color=blue
size=4.5><TH colspan = 5 bgcolor =#BDB76B>Unit
specification</TH></font><TR bgcolor =#FFFFE0><TH>Major
specification</TH><TH>Description</TH><TH>Inspected
by</TH><TH>Status</TH><TH>Completed
%</TH></TR>";
while
select
dngresAgreementUnitSpecification where
dngresAgreementUnitSpecification.UnitNum == dngrsUnitHandover.UnitNum
&& dngresAgreementUnitSpecification.BuildingID ==
dngrsUnitHandover.BuildingId
{
bodyText += strFmt("<TR><TD
bgcolor =#FFFFE0>%1</TD><TD bgcolor =#FFFFE0>%2</TD><TD
bgcolor =#FFFFE0>%3</TD><TD bgcolor =#FFFFE0>%4</TD><TD
bgcolor =#FFFFE0>%5</TD></TR>",dngresAgreementUnitSpecification.MajorSpecification,dngresAgreementUnitSpecification.MajorSpecDescription(),HcmWorker::find(dngresAgreementUnitSpecification.Inspectedby).name(),dngresAgreementUnitSpecification.Status,dngresAgreementUnitSpecification.CompletedPercent);
}
bodyText += "</TABLE>";
bodytext2 +="<TABLE
border=1 style=width:1000px cellspacing=0 cellpadding=0><font color=blue
size=4.5><TH colspan = 5 bgcolor =#BDB76B>Changeorder
specification</TH></font><TR bgcolor =#FFFFE0><TH>Major
specification</TH><TH>Description</TH><TH>Inspected
by</TH><TH>Status</TH><TH>Completed
%</TH></TR>";
while
select
dngrsWorkCompletionChangeOrderSpec where
dngrsWorkCompletionChangeOrderSpec.UnitNum == dngrsUnitHandover.UnitNum
&& dngrsWorkCompletionChangeOrderSpec.BuildingID ==
dngrsUnitHandover.BuildingId
{
bodytext2 += strFmt("<TR><TD
bgcolor =#FFFFE0>%1</TD><TD bgcolor =#FFFFE0>%2</TD><TD
bgcolor =#FFFFE0>%3</TD><TD bgcolor =#FFFFE0>%4</TD><TD
bgcolor =#FFFFE0>%5</TD></TR>",dngrsWorkCompletionChangeOrderSpec.MajorSpecification,dngrsWorkCompletionChangeOrderSpec.MajorSpecificationDesc(),HcmWorker::find(dngresAgreementUnitSpecification.Inspectedby).name(),dngresAgreementUnitSpecification.Status,dngresAgreementUnitSpecification.CompletedPercent);
}
bodytext2 += "</TABLE>";
bodyText3 += "<TABLE
border=1 style=width:1000px cellspacing=0 cellpadding=0><font color=blue
size=4.5><TH colspan = 5 bgcolor =#BDB76B>Document
details</TH></font><TR bgcolor =#FFFFE0><TH>Document
ID</TH><TH>Description</TH><TH>Inspected
by</TH><TH>Status</TH><TH>Completed
%</TH></TR>";
while
select DNGRSDocumentList where DNGRSDocumentList.SalesAgreementID ==
dngrsUnitHandover.SalesAgreementId
{
bodyText3 += strFmt("<TR><TD
bgcolor =#FFFFE0>%1</TD><TD bgcolor =#FFFFE0>%2</TD><TD
bgcolor =#FFFFE0>%3</TD><TD bgcolor =#FFFFE0>%4</TD><TD
bgcolor =#FFFFE0>%5</TD></TR>",DNGRSDocumentList.DocumentID,DNGRSDocumentList.DocumentIDDescription(),HcmWorker::find(dngresAgreementUnitSpecification.Inspectedby).name(),dngresAgreementUnitSpecification.Status,dngresAgreementUnitSpecification.CompletedPercent);
}
bodyText3 += "</TABLE>";
Fullbody = bodyText + "\n" + "<BR>"
+ bodytext2 + "\n" + "<BR>" + bodyText3;
this.sendEmail(CustTable::find(dngrsUnitHandover.Customer).email(),
CustTable::find(dngrsUnitHandover.Customer).name(), "Unit
handover status", Fullbody,true);
}
Send email:
private boolean sendEmail(
Email _applicantEmail,
DirPartyName _applicantName,
HRMApplicationEmailTemplateSubject _mailSubject,
CCMailBody _mailBody,
Boolean _previewEmail)
{
boolean ret;
SmmOutlookEmail smmOutlookEmail;
ccSysInetMail mail;
if(!_previewEmail)
{
mail = new
ccSysInetMail();
mail.sendMail(_applicantEmail,
_mailSubject, _mailBody, false);
if(!mail.mapiStatus())
{
info(strfmt("@SYS31964", _applicantName));
ret = true;
}
}
else
{
smmOutlookEmail = new SmmOutlookEmail();
if
(smmOutlookEmail.createMailItem())
{
smmOutlookEmail.addEMailRecipient(_applicantEmail);
smmOutlookEmail.addSubject(_mailSubject);
smmOutlookEmail.isHTML(true);
smmOutlookEmail.addBodyText(_mailBody);
smmOutlookEmail.sendEMail(smmSaveCopyOfEmail::No);
ret = true;
}
}
return
ret;
}
Substitute Bookmark:
private Container substituteBookmarks(
Container _bookmarks,
HRMApplicationEmailTemplateSubject _mailSubject,
CCMailBody _mailBody,
HRMApplication _hrmApplication,
HRMApplicationBookmark _hrmApplicationBookmark)
{
Counter fieldCounter;
str tableName,
fieldName;
LabelString bookmark,
bookmarkValue;
for
(fieldCounter=1; fieldCounter <= conlen(_bookmarks); fieldCounter++)
{
bookmark = conpeek(_bookmarks, fieldCounter);
[tableName, fieldName] =
HrmApplicationWordBookmark::splitBookmark(bookmark);
[bookmark, bookmarkValue] =
_hrmApplicationBookmark.bookmarkAndValue(tableName, fieldName, _hrmApplication,
true);
if
(strScan(_mailSubject, bookmark, 1, strlen(_mailSubject)))
{
_mailSubject =
strReplace(_mailSubject, bookmark, '%1');
_mailSubject = strfmt(_mailSubject, bookmarkValue);
}
if
(strScan(_mailBody, bookmark, 1, strlen(_mailBody)))
{
_mailBody = strReplace(_mailBody,
bookmark, '%1');
_mailBody = strfmt(_mailBody, bookmarkValue);
}
}
return
[_mailSubject, _mailBody];
}