Tue 25 Oct 2005
Asynchronous App Engine Process With Parameters
Posted by ChiliJoe under PeopleSoft • Tips & Techniques • App EngineTo call a synchronous App Engine process via PeopleCode, use the CallAppEngine() builtin function. Any run parameters for the App Engine can be passed through a record specified in the function parameters. The record field values are loaded to the App Engine program’s state record(s) when it runs.
If attempting to initiate an App Engine process asynchronously, the only way to do so is through the ProcessRequest class — the PeopleCode API for the Process Scheduler. Unlike CallAppEngine(), there is no straightforward way to pass parameters to the scheduled process. Following are 2 methods for passing parameters to an App Engine process.
Method 1: Using AEREQUESTTBL & AEREQUESTPARM
These two tables are used by the Application Engine Process Request Page. We can also utilize these two tables to pass parameters to an App Engine we initiated through the ProcessRequest class. When an App Engine program is initiated by Process Scheduler, part of its initialization process is to look at PS_AEREQUESTTBL table. This table is keyed by OPRID, RUN_CNTL_ID, and AE_APPLID. If a row is matched to this table that identifies the current process, it then checks PS_AEREQUESTPARM. Each child row in PS_AEREQUESTPARM represents a state record field value. BIND_VAR specifies the fieldname, whereas BIND_VALUE specifies the value for that field. When App Engine initializes, the state record is prepopulated with the values from PS_AEREQUESTPARM. The following code sample populates PS_AEREQUESTPARM with 2 rows such that when the App Engine process runs, it will have SAMPLE_AET.TEXT1 prepopulated with &textparm1 and SAMPLE_AET.TEXT2 is prepopulated with &textparm2.
Local Record &RequestTbl, &RequestParm;
&RequestTbl = CreateRecord(Record.AEREQUESTTBL);
&RequestTbl.OPRID.Value = %UserId;
&RequestTbl.RUN_CNTL_ID.Value = "Run_Control_ID_1";
&RequestTbl.AE_APPLID.Value = "AE_PROGID";
&RequestTbl.PROCESS_FREQUENCY.Value = "A";
&RequestTbl.AE_PROCESS_STATUS.Value = "N";
&RequestTbl.PROCESS_ORIG.Value = "N";
&RequestTbl.Delete();
&RequestTbl.Insert();
&RequestParm = CreateRecord(Record.AEREQUESTPARM);
&RequestParm.OPRID.Value = %UserId;
&RequestParm.RUN_CNTL_ID.Value = "Run_Control_ID_1";
&RequestParm.AE_APPLID.Value = "AE_PROGID";
&RequestParm.AE_STATE_RECNAME.Value = "SAMPLE_AET";
&RequestParm.AE_BIND_VAR.Value = "TEXT1";
&RequestParm.AE_BIND_VALUE.Value = &textparm1;
&RequestParm.Delete();
&RequestParm.Insert();
&RequestParm.AE_STATE_RECNAME.Value = "SAMPLE_AET";
&RequestParm.AE_BIND_VAR.Value = "TEXT2";
&RequestParm.AE_BIND_VALUE.Value = &textparm2;
&RequestParm.Delete();
&RequestParm.Insert();
/* Create the ProcessRequest Object */
Local ProcessRequest &RQST = CreateProcessRequest();
/* Set all the Required Properties */
&RQST.RunControlID = "Run_Control_ID_1";
&RQST.ProcessType = "Application Engine";
&RQST.ProcessName = "AE_PROGID";
/* Schedule the Process */
&RQST.Schedule();
If &RQST.Status = 0 Then
WinMessage("Process is scheduled", 0);
End-If;
In AEREQUESTTBL, make sure PROCESS_FREQUENCY is set to Always and AE_PROCESS_STATUS is set to New to ensure process scheduler will execute the process.
- Method pros:
- No need to setup a run control table.
- Method cons:
- Using the delivered tables PS_AEREQUESTTBL & PS_AEREQUESTPARM for all your processes could have a maintenance impact.
Method 2: Using a Run Control Table
In this method, a run control table is created. It is populated prior to scheduling the process. In the following sample, the run control table has the fields TEXT1 and TEXT2 that we want to pass to the AE program.
Local Record &RunControl = CreateRecord(Record.AE_RUNCNTL);
&RunControl.OPRID.Value = %UserId;
&RunControl.RUN_CNTL_ID.Value = "Run_Control_ID_1";
&RunControl.TEXT1.Value = &textparm1;
&RunControl.TEXT2.Value = &textparm2;
&RunControl.Delete();
&RunControl.Insert();
/* Create the ProcessRequest Object */
Local ProcessRequest &RQST = CreateProcessRequest();
/* Set all the Required Properties */
&RQST.RunControlID = "Run_Control_ID_1";
&RQST.ProcessType = "Application Engine";
&RQST.ProcessName = "AE_PROGID";
/* Schedule the Process */
&RQST.Schedule();
If &RQST.Status = 0 Then
WinMessage("Process is scheduled", 0);
End-If;
In the App Engine program, to retrieve the values from the run control table, add a step to pass those values to the state record. The step would contain a SQL action. It will contain the following:
%SelectInit(SAMPLE_AET.TEXT1, SAMPLE_AET.TEXT2)
Select TEXT1, TEXT2
From PS_AE_RUNCNTL
Where OPRID = %OperatorId
And RUN_CNTL_ID = %RunControl
Succeeding steps will have access to the state record fields which is now populated from the values in the run control table. Note that %RunControl is an App Engine meta-SQL variable and is only available in a SQL step.
- Method pros:
- No need to update system tables PS_AEREQUESTTBL and PS_AEREQUESTPARM. This method can easily be modified to allow more rows on the run control table per run control ID.
- Method cons:
- Needs to create an additional SQL table.
Applies to PeopleTools version: 8.4+
March 1st, 2006 at 9:49 pm
Very nice site and very detailed information. However, I’m specifically looking for tips on using CallAppEngine PCode (in FieldChange event for when user clicks on the hyperlink/button in the page) to call the PSQUERY delivered AppEngine (Tools 8.45.11). I’m doing this b/c I need the query to run thru process scheduler. Also, the query has multiple prompts. Any insight? Thanks in advance