PeopleCode | How to schedule a new process request
A. Basic Use
When writing a piece of PeopleCode, you might want to run an external process or report as part of the routine. Assuming the external process has already been defined as a ‘Process’ (in PeopleTools -> Process Scheduler -> Processes), you can go ahead and schedule an immediate run of the process by including the following PeopleCode:
Local ProcessRequest &RQST; /* Schedule the report */ &RQST = CreateProcessRequest(); &RQST.RunControlID = %OperatorId; &RQST.ProcessType = "Application Engine"; &RQST.ProcessName = "AENAME"; &RQST.RunLocation = &installRec.SERVER_NAME.Value; &RQST.RunDateTime = %Datetime; &RQST.Schedule();
B. Further Notes
A few points to note about the code above:
- If the process requires a run control record (with process parameters), be sure to set this up in advance with the same Operator ID and Run Control ID.
- If the process relies on data being saved in advance (such as data on the current component, or the run control record mentioned in the prior point), make sure all data is saved before calling ‘CreateProcessRequest’. On an online page, a ‘SavePostChange’ event would be a good place for making the call.
- This code is equivalent to the user manually going into a run control page and clicking the ‘Run’ button to schedule the process. In other words, the above code only schedules the process, meaning that you need to wait for the process to run to completion. Therefore, never include any code directly after the above PeopleCode that assumes the process has already finished. Instead, implement a ‘sleep’ routine that temporarily halts the code until the process has finished (refer to Tip 003).
- The ‘RunLocation’ field is generally ‘PSUNX’ or ‘PSNT’, and indeed, this value is often hardcoded directly into the code. However, a better solution is to set up an Installation record which defines the SERVER_NAME (as in the example above), or run the following SQL to determine which server would be most appropriate at run time:
SELECT a.servername FROM ps_serverclass a , ps_pmn_srvrlist b WHERE a.servername = b.servername AND a.prcstype = 'Application Engine' AND b.serverstatus = '3';
If the process being called is not an App Engine, remember to replace ‘Application Engine’ in the above statement with the correct process type.
- The ‘RunDateTime’ field in the example above is set for immediate execution. However, this can be set to a future time if you prefer to delay execution for whatever reason.
See Also:
Tip 003: Sleep Function
Tip 015: Calling an App Engine from within PeopleCode