Create a PDF file in PeopleCode using the Query API
By Chris Malek | Tue, Feb 14, 2012
Have you ever wanted to create a PDF file in Application Engine or Peoplecode? Well it turns out it is not too hard. The PDF will be somewhat limited but this method can still be very useful in some situations like:
- You have an application engine that logs items to a table and you want to generate a PDF of the warnings and errors.
- You want to report on the rows inserted into a processing table
- You want a basic PDF output based on some SQL
In the example below, we have a query called “CHG_ERROR_LIST” that is
defined in query manager. The query does not have any prompts. However,
we still have to pass the RunToFile
method a dummy
PromptRecord object as it is a requirement for the query API.
Note: I have mocked a function called “getWritablePath” that will pass back a directory that is writable to the application server or process scheduler. This is very specific to your installation and where you want the file to go. I have hard coded a value for example purpose so don’t use this as model for your code. You may want to take a look at this article about How to get files to show up in the process monitor.
The resulting PDF for this test code will be in
/appl/shared\_files/queryToFile.pdf
which I can guarantee
is not valid for your environment.
function getWritablePath() returns string
/* This function should return a writable path in your installation. */
return "/appl/shared_files/";
end-function;
Function queryToFile()
Local ApiObject &objQry;
&objQry = %Session.GetQuery();
If &objQry.open("CHG_ERROR_LIST", True, True) = 0 Then
Local string &path;
&path = getWritablePath() | "queryTofile.pdf";
If &objQry.RunToFile(&objQry.PROMPTRECORD, &path, %Query_PDF, 0) = 0 Then
/* A zero return means success which is counter-intuitive */
End-If;
&objQry.CLOSE();
End-If;
Additional Reading
Article Categories
Chris Malek
Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.
About Chris Work with ChrisPeopleSoft Simple Web Services (SWS)
Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.
Integration Broker - The Missing Manual
I am in the process of writing a book called "Integration Broker - The Missing Manual" that you can read online.