PeopleCode | Generate a BI Publisher report and display the result
A. BI Publisher in PeopleCode
Once you’ve created a report through BI Publisher, you can then generate that report in PeopleCode and display the end result directly to the user. Below, we will consider two approaches for generating a BI Publisher report. The first uses an XML file for the data source, while the second uses a PS Query.
B. Using XML
We start with the XML approach. Note that this example assumes the XML file has already been created and is stored on the ‘files’ directory under the current working directory. (The process of creating the XML file is beyond the scope of the current post.)
import PSXP_RPTDEFNMANAGER:ReportDefn; /* Declare variables */ Local PSXP_RPTDEFNMANAGER:ReportDefn &oRptDefn; Local Record &rcdQryPrompts; /* Call the XML Publisher report */ &oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn("REPORT_NAME"); &oRptDefn.Get(); &oRptDefn.SetRuntimeDataXMLFile(GetCWD() | "/files/DATA_FILE.xml"); /* Generate report */ &oRptDefn.ProcessReport("TEMPLATE_NAME", %Language, %Date, "PDF"); /* Perform a save */ CommitWork(); /* Display the report to the user */ &oRptDefn.DisplayOutput();
C. Using PS Query
The second example uses PS Query as the data source. To make this example more realistic, the query requires three input parameters.
import PSXP_RPTDEFNMANAGER:ReportDefn; /* Declare variables */ Local PSXP_RPTDEFNMANAGER:ReportDefn &oRptDefn; Local Record &rcdQryPrompts; /* Call the XML Publisher report */ &oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn("REPORT_NAME"); &oRptDefn.Get(); /* fill query runtime prompt record */ &rcdQryPrompts = &oRptDefn.GetPSQueryPromptRecord(); /* Populate query prompts */ &rcdQryPrompts.OPRID.Value = ¶m1; &rcdQryPrompts.RUN_CNTL_ID.Value = ¶m2; &rcdQryPrompts.EMPLID.Value = ¶m3; &oRptDefn.SetPSQueryPromptRecord(&rcdQryPrompts); /* Generate report */ &oRptDefn.ProcessReport("TEMPLATE_NAME", %Language, %Date, "PDF"); /* Perform a save */ CommitWork(); /* Display the report to the user */ &oRptDefn.DisplayOutput();
The system takes a slightly artificial approach here by treating the PS Query prompts as if they were part of a single record. The ‘GetPSQueryPromptRecord’ method creates a temp record consisting of three fields (the three prompts :1, :2 and :3). You can then go ahead and populate the record fields in the same way that you would for a standard record.