With the continued evolution of PeopleCode, including features like the XML Publisher, I find myself building more and more Application Engines that are primarily PeopleCode based. In many cases, in fact, I’ve got only two steps: a SQL action to populate the state record with the run control and a PeopleCode action to do the work.
Mostly it was habit. The SelectInit has been my friend for a long time. But I just realized I can bring the run control record directly into the PeopleCode step without the need of a SQL step to populate it first.
The state record is always available to a PeopleCode event with a simple GetRecord. The app engine always populates the state record with the process instance—you get that for free. Armed with that, a SQLExec to the process request table gets you the Run Control Id. Since run control tables are keyed by Run Conrol Id and User Id, you’re in business.
Local string &id;
SQLExec("SELECT RUNCNTLID FROM PSPRCSRQST WHERE PRCSINSTANCE = :1", GetRecord().PROCESS_INSTANCE.Value, &id);
Local Record &runControl = CreateRecord(Record.G9_JOBC_DESC_RC);
&runControl.OPRID.Value = %UserId;
&runControl.RUN_CNTL_ID.Value = &id;
course, this counts on the app engine running through the process
scheduler. Without that there’s no row in the process request table. If
you like to run app engines directly from the App Designer this won’t
work. (If you're debugging, just hard code your Run Control Id, then you're back in business.)