Scheduling a Process from PeopleCode

The process scheduler provides a good standard way to launch a process.  You simply add a subpage to your run control page, and the delivered “Run” button does all of the work for you.  But sometimes, you want to run the process other ways.  Sometimes, you might want to create a more customized feel on a end-user page and launch a process from a push button.  Or, you might want to launch an additional process from an App Engine program.

In this post, I would like to drop notes to make this easier the next time I need to do it.

Using the Delivered Process Scheduler Subpage

Creating a basic run control page is pretty easy.  The thing that I forget is the exact name of the sub page to add.  Here’s the name:


You just add the subpage at the top:

Process Scheduler Subpage

This gives you the standard Run button at the top of your page:

Run Control Subpage Online

While I’m at it, the other thing that I always forget is the search record to use for a run control component.  The delivered search record name is:


Run Control Search Record

If it’s easier, you can clone the System Process Requests Page…

  • Component: PRCSMULTI

System Process Requests Page

Scheduling with PeopleCode

To manually schedule a process, you can use PeopleCode as simple as this:

Local ProcessRequest &rqst;
&rqst = CreateProcessRequest();
&rqst.ProcessType = "Application Engine";
&rqst.ProcessName = "AE_NAME";
&rqst.RunControlID = "PS";

The ProcessRequest API class is what does the trick.  The CreateProcessRequest() built-in function instantiates it and gives you a new object to work with.  Next, you need to use the ProcessType and ProcessName properties to tell it which process you want to run.  These point it to the Process definition defined with the Process Scheduler pages.  The RunControlID property points it to the parameters for the program.  Finally, the Schedule() method schedules the process to run in the Process Scheduler.

Waiting for the Process to Finish

Sometimes if it is a quick running program, you may want your code to wait for it to finish.  For example, the Budget Check is like that in Financials.  The user clicks a button to launch the budget check and control does not return back to the user until the program finishes.

Here’s some code that will keep checking until the process finishes.  It assumes that you used the &rqst variable to launch the process:

Local number &instance;
Local number &runStatus;
Local JavaObject &thread;

If &rqst.Status = 0 Then;
     &instance = &rqst.ProcessInstance;
     SQLExec("SELECT RUNSTATUS FROM %Table(:1) WHERE PRCSINSTANCE = :2", Record.PSPRCSRQST, &instance, &runStatus);
     While &runStatus = 5 Or
           &runStatus = 6 Or
           &runStatus = 7;
          SQLExec("SELECT RUNSTATUS FROM %Table(:1) WHERE PRCSINSTANCE = :2", Record.PSPRCSRQST, &instance, &runStatus);
          &thread = GetJavaClass("java.lang.Thread");
     MessageBox(0, "", 0, 0, "Process completed with status: " | &runStatus);
     MessageBox(0, "", 0, 0, "Error launching process");

The Status property tells you whether the process was scheduled successfully.  If it didn’t launch, there’s no point in waiting for anything.  Next, the ProcessInstance property tells you what the instance number is.  You can use that to check the status.

The PSPRCSQST is the table that stores all of the status for the processes.  This is basically what the Process Monitor shows you.  The code is checking for status 5, 6, or 7, which is Queued, Initiated, or Processing.

PeopleCode does not have a sleep function in it. Instead, this code uses Java’s sleep function built into the Java Thread class.

Additional Information

PeopleBooks has some pretty good information itself about scheduling processes.  Here are some quick links to that information:

2 thoughts on “Scheduling a Process from PeopleCode

  1. Hi,

    I have Question. How would i mark the process to No Success. If any of the scheduled process is through this code is failed.

    1. Really, the process itself should update the the process to No Success. For example, if you call Error() in App Engine PeopleCode, it will stop that process mark it as No Success.

      The ProcessRequest class does have a method called UpdateRunStatus() that lets you update the status. You could try this:
      Local ProcessRequest &p = CreateProcessRequest();
      &p.ProcessInstance = 12345;
      &p.RunStatus = 10;

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.