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:
This gives you the standard Run button at the top of your page:
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:
If it’s easier, you can clone the System Process Requests Page…
- Component: PRCSMULTI
- Page: PRCSSAMPLEPNL1
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"; &rqst.Schedule();
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"); &thread.sleep(1000); End-While; MessageBox(0, "", 0, 0, "Process completed with status: " | &runStatus); Else; MessageBox(0, "", 0, 0, "Error launching process"); End-If;
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.
PeopleBooks has some pretty good information itself about scheduling processes. Here are some quick links to that information: