You are on page 1of 5

Example: Publish a Report Based on PS Query

This is a code snippet example for publishing a report based on PS Query:


import PSXP_RPTDEFNMANAGER:*;

/* get report definition object */


&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn (&sRptDefn);
&oRptDefn.Get();
/* fill query runtime prompt record */
&rcdQryPrompts = &oRptDefn.GetPSQueryPromptRecord();
If Not &rcdQryPrompts = Null Then
&oRptDefn.SetPSQueryPromptRecord(&rcdQryPrompts);
End-If;
/*generate report*/
&oRptDefn.ProcessReport (&sTmpltID, &sLangCd, &AsOfDate, &sOutFormat);
/*publish report */
&oRptDefn.Publish(&sPrcsServerName,"",&sFolder, &prcsInstId);

Example: Print a Report Based on XMLFile


This is a code snippet example for printing a report based on XMLFile:
import PSXP_RPTDEFNMANAGER:*;

/* get report definition object */


&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn (&sRptDefn);
&oRptDefn.Get();
/* pass XMLFile to the report definition */
&oRptDefn.SetRuntimeDataXMLFile(&sXMLFilePath);
/*generate report*/
&oRptDefn.ProcessReport (&sTmpltID, &sLangCd, &AsOfDate, &sOutFormat);
/*print report */
&oRptDefn.PrintOutput(&sDestinationPath);

BI Publisher Classes Example


The following example provides a complete example of the code first, then goes through the
program line by line.
Generating and Publishing a Report
In the following example, a report is created from an existing report definition. It is populated with
an already instantiated and populated XmlDoc object, then published.
The following is the complete code sample: the steps explain each line.
import PSXP_RPTDEFNMANAGER:ReportDefn;

Local string &sFileName = "c:\path\filename.xml";


Local string &rptDefnId = "Financial";
Local string &LanguageCode = "ENG";
Local date &effdt = Date(20090821);
Local string &outputfmt = "HTM";

Local string &folderName = "General";


Local string &serverName = "PSNT";
Local PSXP_RPTDEFNMANAGER:ReportDefn &rptDefn;

&rptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&rptDefnId);


&rptDefn.Get();
&rptDefn.SetRuntimeDataXMLFile(&sFileName);
&rptDefn.ProcessReport("", &languageCd, &effdt, &outputfmt);

XML Publisher in PeopleCode


This XML Publisher output is based on the report created in XML Publisher Basics.
PROJECT OBJECTS

STEPS TO IMPLEMENT

1. Create a record (only needs to be a work record for this example).


2. Insert any field into the record and then save the record.
3. Create a new page and place a push button on the page with the field properties set to use your record.field.

4. Save the page.


5. Create a new component and add the page to the component.
6. Modify the component properties to use INSTALLATION as the Search Record. (Save)

7. Add the following PeopleCode to the Component Record Field FieldChange event for your push button.
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* You must reference an application package at the beginning of the event */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
import PSXP_RPTDEFNMANAGER:*;
Local Record &rcdQryPrompts;
Local string &LanguageCd, &MyTemplate, &MyReportName, &OutFormat, &State;
Local date &AsOfDate;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Set XML Publisher report required parameters
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&LanguageCd = "ENG";
&AsOfDate = %Date;
&OutFormat = "PDF";
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Create a PDF using XML Report Definition MY_XMLP_DEMO
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&MyReportName = "MY_XMLP_DEMO";
&MyTemplate = "MY_XMLP_DEMO_1";
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Hard code my State value - would normally pull from a field on the page */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&State = "NY";
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Declare and Instantiate (construct) your Report Definition Object
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
Local PSXP_RPTDEFNMANAGER:ReportDefn &oReportDefn = create
PSXP_RPTDEFNMANAGER:ReportDefn(&MyReportName);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Get a handle on your Report Definition
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&oReportDefn.Get();
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* Since there is a prompt to the query used in this report, you need to
/* provide the value for the prompt
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&rcdQryPrompts = &oReportDefn.GetPSQueryPromptRecord();
If Not &rcdQryPrompts = Null Then
&oReportDefn.SetPSQueryPromptRecord(&rcdQryPrompts);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* Provide a value to the State Prompt
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
&rcdQryPrompts.STATE.Value = &State;

*/
*/
*/
*/

*/
*/
*/

End-If;
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Kick of the report process
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&oReportDefn.ProcessReport(&MyTemplate, &LanguageCd, &AsOfDate, &OutFormat);
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* CommitWork must be called prior to displaying the output since the
/* application package performed work and SQL statements. If you do
/* not commit the work performed to this point you will receive an
/* error like Think-time PeopleCode event (ViewAttachment), but a SQL
/* update has occurred in the commit interval. (2, 148)
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
CommitWork();

*/
*/
*/
*/
*/
*/
*/

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Display Report to the user
*/
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&oReportDefn.DisplayOutput();
8. Add the component to a menu. (Save)
9. Register the component with the appropriate security given to your user.
TEST THE REPORT GENERATION USING PEOPLECODE.

1. Browse to your test page.

2. Press the push button.


3. You should be prompted to view or save the output file.

You might also like