Monday, December 19, 2011

HTML based notifications

PeopleSoft provides functions and procedures to send email notifications. Most of the times we send simple text messages and attach reports, generally in PDF format to these notifications. The following post, explores the possibility of generating a report via XMLP and then sending a notification to an email client like MS Outlook in HTML format. The distribution type of "email" that is natively available via XMLP just doesn't cut it. Its very tedious to change the subject/body of the notification and then the report is sent as an attachment and not the body the notification.

For this POC, I am using a HR 9.1 PeopleSoft system running on PT 8.51.10 and my email client is MS Outlook 2007. The exchange server is running MS Exchange 2003. I am executing the following code via an AE program. Some changes needed if using it via an online trigger like FieldChange.
I will be using the SendMail function instead of PeopleSoft MultiChannel Framework mail classes. To do the same via MCF mail classes is another post, some other day.

/* this section details the steps to create the report in HTM format and store it in a folder location */
&REPORTDEFN.OutDestination = &dir | "\"; /* This will create the output under the temp directory used by the process scheduler */
&REPORTDEFN.ProcessReport(&template, "", %Date, "HTM"); /* generating the report in HTM format */

/* the following section, sets up the parameters of the SendMail function and sends the notification */
&EmailSQL = CreateSQL("select EMAIL_ADDR from PS_EMAIL_ADDRESSES where EMPLID = :1 and PREF_EMAIL_FLAG = 'Y'", &EmplID);
If All(&email_addr) Then
      &MAIL_FLAGS = 0;
      &MAIL_TO = &email_addr;
      &MAIL_CC = "";
      &MAIL_BCC = "";
      &MAIL_SUBJECT = "PeopleSoft Report";
/* here I am reading the htm report file in UTF-8 mode and then use that to populate the "body" variable */
      &fullfile = "";
      &reportfilepath = &dir | "\N_REPORT.htm";
      &html_file = GetFile(&reportfilepath, "R", "UTF-8", %FilePath_Absolute);
      While &html_file.ReadLine(&Text)
         &fullfile = &fullfile | &Text;
      &MAIL_TEXT = &fullfile;

      /* this will takre care of only one image */
      &imgpath = &dir | "\*.png";
      &FileList = FindFiles(&imgpath, %FilePath_Absolute);
      &filepath = &FileList.Shift();
      &MAIL_FILES = &filepath;
      &pos = Find("xdo", &filepath);
      &MAIL_TITLES = Substring(&filepath, &pos, Len(&filepath) - &pos + 1);
      &CONTTYPE = "Content-type: text/html; charset=utf8";
      &MAIL_SENDER = "";
      If Not (&RET = 0) Then
         Warning ("Return status from mail = " | &RET);
      Warning ("No Email Addresses found for " | &EmplID);

Thats it. It produces a nice and chic looking HTML notification.

Tuesday, December 13, 2011

XMLP Output Options

Following are the different ways to display a XMLP report, via peoplecode.

/* initialize */
&reportdefn = create PSXP_RTPDEFNMANAGER:ReportDefn(&report);
&template = &reportdefn.GetDefaultTemplateID();

/* this will create the PDF report output under c:\temp\ */
/* useful when generating report via an AE program */
&reportdefn.OutDestination = "c:\temp\";

/* without setting &reportdefn.OutDestination as mentioned above the PDF report will be written to the report respository and available via the Report Manager */

/* this will open the output in a new browser window. In this case code is executed on the appserver as against process scheduler in the above two scenarios */

Based on the above scenarios here is cool trick to show the report under process monitor (view/log trace) instead of the report manager.
&reportdefn.OutDestination = &dir | "\";