Sunday, September 23, 2012

PeopleCode to Schedule Process and wait until that executed successfully


Following sample PeopleCode can be used to schedule any process using PeopleCode (Application Engine PeopleCode or in any other event). This sample PeopleCode is used to schedule Crystal report and email the same to the specific user. First it override the parameter set in the Crystal report process definition than it schedules the Crystal Report process and wait until that process resulted into success.

Local ProcessRequest &Rqst;
Local string &Subject, &Text, &EmailId, &Running, &Finish;
Local integer &PrcsInst;

/*use sql exe to update parameter of crystal report process definition*/
TEST_STATE_AET.PARMLIST.Value = "-ORIENTP " | Char(34) | TEST_STATE_AET.OPRID.Value | Char(34) | " " | Char(34) | TEST_STATE_AET.PROCESS_INSTANCE.Value | Char(34);

&Rqst = CreateProcessRequest();
&Rqst.RunControlID = TEST_STATE_AET.RUN_CNTL_ID.Value;
&Rqst.ProcessType = "Crystal";
&Rqst.ProcessName = "TESTCRST";
&Rqst.RunLocation = "PSNT";
&Rqst.OutDestType = "Email";
&Rqst.OutDestFormat = "PDF";
&Rqst.OutDest = TEST_STATE_AET.EMAILID.Value;
&Rqst.EmailSubject = "TEST MAIL";
&Rqst.EmailText = "TEST MAIL";
&Rqst.EmailAttachLog = False;
&Rqst.Schedule();
&PrcsInst = &Rqst.ProcessInstance;

/* wait until PROCESS finish */
/*check process running status check process completed or not*/

&Running = "S";
While &Running = "S"
   SQLExec("select 'x' from psprcsrqst where PRCSINSTANCE = :1 and runstatus  in ('5','6','7','14')", &PrcsInst, &Finish);
   If None(&Finish) Then
      &Running = "N"
   End-If;
End-While;

2 comments:

  1. Good Job. However this can be improved with a timer otherwise it will cause performance issue executing the same sql over and over again!.
    Keep posting!

    ReplyDelete