Tuesday, July 5, 2011

Schedule Application Engine through Peoplecode

The following sample code can be used to Schedule App Engine through PeopleCode.

Code to Schedule App Engine thru PeopleCode:

Local ProcessRequest &MYRQST;

&MyAppName = "MY_APP";
&MYRQST = CreateProcessRequest("Application Engine", &MyAppName);
&MYRQST.RunControlID = "TEST";
&MYRQST.RunLocation = "PSUNX";
&MYRQST.Schedule();

If &MYRQST.Status = 0 Then /* if Schedule status is success */

End-If;
Code to know whether the scheduled App Engine ran to success or not:
If &MYRQST.Status = 0 Then /* if Schedule status is success */

&LOOP = 0;
While &LOOP = 0
SQLExec("SELECT A.DISTSTATUS, A.RUNSTATUSDESCR FROM PS_PMN_PRCSLIST A WHERE A.PRCSNAME = :1 AND A.PRCSINSTANCE = (SELECT MAX(B.PRCSINSTANCE) FROM PS_PMN_PRCSLIST B WHERE B.PRCSNAME = A.PRCSNAME)", &MyAppName, &POSTED, &STATUS);

If &STATUS = "Success" And
&POSTED = 5 Then /* Posted */
&LOOP = 1
End-If;

If &STATUS = "Success" And /* Not Posted */
&POSTED = 4 Then
&LOOP = 2
End-If;

If &STATUS = "No Success" Or
&STATUS = "Error" Then
&LOOP = 3;
End-If;

End-While;

If &LOOP = 1 Then
MessageBox(0, "", 27333, 594, ""); /* Success Msg */
Else
If &LOOP = 2 Or
&LOOP = 3 Then
MessageBox(0, "", 27333, 595, ""); /* Failed Error Msg */
End-If;
End-If; /* If &LOOP = 1 Then */
End-If;
 
The below function can also be used for schedule application engine: (Alternative Function)
Function ScheduleSetupAEProcess(&RESULT_SET_COMP)
&RUN_SETUP_AE_REQST = CreateProcessRequest("Application Engine", "PTLT_SETUP");
&REC_IMPL_RUN = CreateRecord(Record.PTLT_PROJ_RUN);

/* Run Control ID = Configuration Set Name */
&RUN_CNTL_ID = &RESULT_SET_COMP;

&RUN_SETUP_AE_REQST.RunControlID = &RUN_CNTL_ID;
&RUN_SETUP_AE_REQST.Schedule();

If &RUN_SETUP_AE_REQST.Status = 0 Then
&PROCESS_INSTANCE = &RUN_SETUP_AE_REQST.ProcessInstance;
/* Insert into Setup Manager Run Control Record */
&REC_IMPL_RUN.OPRID.Value = %OperatorId;
&REC_IMPL_RUN.RUN_CNTL_ID.Value = &RUN_CNTL_ID;
&REC_IMPL_RUN.PTLT_PROJ_NAME.Value = &RESULT_SET_COMP;
&REC_IMPL_RUN.PROCESSINSTANCE.Value = &PROCESS_INSTANCE;

If Not &REC_IMPL_RUN.Update() Then
&REC_IMPL_RUN.Insert();
End-If;
Else
Error MsgGet(218, 154, "Process cannot be scheduled");
End-If;
End-Function;





5 comments:

Josh Bigler said...

Hi,

I've seen various samples of this code but I don't understand how to incorporate a run control record (or 2) in this process. I'm trying to run the SCRTY_CLSUPD app engine (which uses 2 Run Control tables) to refresh row security on the fly. PS HCM 9.0, Tools 8.49.

Any suggestion would be appreciated.

Thanks

Pawan Mundhra said...

Before scheduling you can populate your run control record using insert method or using sql method etc.. And then use schedule method to schedule the process.
Hope will help you this.

ppl soft said...

Hi Pawan,

I have a runcontrol page wherein I will enter the process frequency and first run time and then process should run for the times entered in frequency in single day. How can I achieve this with the code suggested by you

Pawan Mundhra said...

You can use a preprocessor which is schedule to run on every hour (based on your requirement) and the preprocessor reads the frequency and trigger your application engine based on the frequency you have set in the page.

ppl soft said...

Hi Pawan,

Thanks a lot for the reply. Can you please give an example, how to use preprocessor, from where to get it. I am sorry but this is new to me.

Post a Comment