Friday, March 7, 2014

Sending Batch Emails using Application Engine

From the Application Designer choose
1) File – New and select Application Engine.
2) You will see new definition created for you containing the MAIN section with a step
entitled STEP01.
3) Simply right click your mouse on the step (STEP01) and choose Insert Action.
4) A new action will be inserted and will default to SQL.
5) Change this action to PeopleCode.
6) Save your program
7) Then double click on the PeopleCode action. Now you are ready to insert the code
below. I will fully explain this code.

REM **********************************************;
REM ** Instantiate the record and SQL objects to obtain data *;
REM **********************************************;
&MY_DATA_REC = CreateRecord(Record.EMPLOYEES);
&MY_DATA_SQL = CreateSQL("%selectall(:1) WHERE PAYGROUP = :2");
&MY_DATA_SQL.Execute(&MY_DATA_REC, "OUR_PAYGROUP");
REM **********************************************;
REM ** Loop through all of the data one row at a time for *;
REM ** all rows *;
REM **********************************************;
While &MY_DATA_SQL.Fetch(&MY_DATA_REC);
REM **********************************************;
REM ** Set all necessary email parameters REM **********************************************;
&MAIL_FLAGS = 0;
&MAIL_TO = &MY_DATA_REC.EMAILID.Value;
&MAIL_CC = "";
&MAIL_BCC = "";
&MAIL_SUBJECT = "Pay check is Available Online for Viewing";
&NAME = &MY_DATA_REC.NAME.Value;
&MAIL_TEXT_BODY = "Dear " | &NAME | ", Your paycheck is now available for viewing online.";
&MAIL_FILES = "";
&MAIL_TITLES = "";
REM **********************************************;
REM ** Send the email message for the current employee;
REM **********************************************;
&RET_CODE = SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT_BODY,
&MAIL_FILES, &MAIL_TITLES);
REM ********************************************************;
REM ** Check the status code to ensure the mail was sent successfully;
REM ********************************************************;
If Not (&RET_CODE = 0) Then
WinMessage("Return status from mail = " | &RET_CODE);
End-If;
End-While;
REM ** Don’t forget to close the SQL stream **;

&MY_DATA_SQL.Close();

No comments:

Post a Comment