Application Engine

Trace Application Engine Processes Using Process Definitions

In this post I will show you how to trace an application engine process using the Process Definitions without setting the trace in the Process Scheduler’s psprcs.cfg configuration file.

Navigate to the process definition of the application engine that you would like to trace (PeopleTools > Process Scheduler > Processes). Go to the Overrride Options tab, and from the Parameter List drop down select Append, and in the edit box next to it add the following line:

-TRACE 7 -TOOLSTRACEPC 4044

TRACE application engine using process definition

Send Emails from PeopleCode (SendMail Function)

You can use the SendMail PeopleCode function to send emails from within PeopleCode. You can also call this function from an Application Engine.

Note: Make sure your SMTP server is configured properly or the SendMail function will fail.

Local string &MAIL_CC, &MAIL_TO, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TITLES, &MAIL_TEXT, &MAIL_FILES, &MAIL_FROM, &REPLYTO, &SENDER;
Local number &MAIL_FLAGS;

&MAIL_FLAGS = 0;
&MAIL_TO = "email-address-message-going-to";
&MAIL_CC = "";
&MAIL_BCC = "";
&MAIL_SUBJECT = "Test email";

Read a File Using File Layout

A sample code to read a file using file layouts and insert data read into a record.

Local File &MYFILE;
Local Record &REC;
Local array of string &ARRAY;
Local string &FILE_DIRECTORY, &FileName;

&FileName = "MY_FILE_NAME.txt";
&FILE_DIRTORY = "/MYDIRECTORY/"
/*open file for reading*/
&MYFILE = GetFile(&FILE_DIRECTORY | &FileName, "R", %FilePath_Absolute);
/*create record object*/
&REC = CreateRecord(Record.MY_RECORD);
&ARRAY = CreateArrayRept("", 0);
/*check if file is open*/
If &MYFILE.IsOpen Then

Email Users Under a Specific Role Name

Here is a quick Application Engine section that looks up user's email addresses under a certain ROLE and sends an email notification regarding, well, what ever you'd like.

send email for a specific role

First, you would need a "Do Select" step to loop through the email addresses (if more than one) and call the PeopleCode step below it to send the email. Your Do Select should have the following SQL:

-- you need to store the email address for the peoplecode step to use and thus the %Select(EMAILID).

Run an SQR From a PeopleSoft Application Engine

Here is a good sample of how to launch an SQR from within PeopleCode. You can use the peoplecode function called “ScheduleProcess”. Here is the example:

&PROCESS_NAME = "SQRNAME";
&PROCESS_TYPE = "SQR Report"; (or "SQR Process")
&RUN_CNTL_ID = "YOUR_RUN_ID";
&RUN_CONTROL = ScheduleProcess(&PROCESS_TYPE, &PROCESS_NAME, "2", &RUN_CNTL_ID, &PRCS_INST);

If &RC != 0 /*"1" = client "2" = server*/
Winmessage("Error: Error Scheduling SQR Process, RC = " | &RUN_CONTROL);
End-If;

Calling an Application Engine from PeopleCode

The PeopleCode below will show you how to call an Application Engine from PeopleCode. Some refer to this as “Real-Time Application Engine Processing.” For example, when a user save’s a page, you may want a specific App engine program to run. You can also execute this code in a field change event.

The following code calls the Application Engine program named YouAppEngProg, and passes it the necessary initialization values.

&MYRECORD = CreateRecord(RECORD.MY_INIT_VALUES);

PeopleSoft Validate AP Business Unit

The select statement below is preformed by AP Voucher Build (AP_VCHRBLD) Application Engine to validate an AP Business Unit:

INSERT INTO %TABLE(VCHR_HDR_QV_ER) (PROCESS_INSTANCE
, BUSINESS_UNIT
, VOUCHER_ID
, MESSAGE_SET_NBR
, MESSAGE_NBR
, FIELDNAME
, MESSAGE_PARM1
, MESSAGE_PARM2
, MESSAGE_PARM3)
SELECT %Bind(PROCESS_INSTANCE)
, HDR.BUSINESS_UNIT
, HDR.VOUCHER_ID
, 7220
, 1
, 'BUSINESS_UNIT'
, HDR.BUSINESS_UNIT
, ' '
, ' '
FROM %TABLE(VCHR_HDR_TMP) HDR
WHERE PROCESS_INSTANCE = %Bind(PROCESS_INSTANCE)
AND BUSINESS_UNIT NOT IN (
SELECT BUSINESS_UNIT

PeopleSoft Validate Vendor ID

The select statement below is preformed by AP Voucher Build (AP_VCHRBLD) Application Engine to validate a Vendor ID:

INSERT INTO %TABLE(VCHR_HDR_QV_ER) (PROCESS_INSTANCE
, BUSINESS_UNIT
, VOUCHER_ID
, MESSAGE_SET_NBR
, MESSAGE_NBR
, FIELDNAME
, MESSAGE_PARM1
, MESSAGE_PARM2
, MESSAGE_PARM3)
SELECT %Bind(PROCESS_INSTANCE)
, HDR.BUSINESS_UNIT
, HDR.VOUCHER_ID
, 7220
, 2
, 'VENDOR_ID'
, HDR.VENDOR_SETID
, HDR.VENDOR_ID
, ' '
FROM %TABLE(VCHR_HDR_TMP) HDR
WHERE HDR.PROCESS_INSTANCE = %Bind(PROCESS_INSTANCE)
AND VENDOR_ID NOT IN (
SELECT VENDOR_ID

Application Engine ReUse Statement in PeopleSoft

The ReUse in Application Engine was brought to my attention by a great blog that I follow regularly.  The original post can be found at PeopleSoftTipster

The ReUse statement setting on an Application Engine is a great way to increase performance. It’s useful when you have a SQL object that is called multiple times, for instance when you have a DoSelect that runs a SQL Step repeatedly, substituting different Bind variables in each time.