Wednesday, 14 May 2014

How to create a XMLP Report with PS Query as data source and using PeopleCode?

What we are trying to achieve?

o   Create a XMLP report in pdf format of the content item information by clicking on a button on the page
o   Screenshot of the content item for the content type ‘COMPETENCY’, with a print button (highlighted in yellow) to the trigger the PeopleCode which generates XMLP report in PDF format.

o   Screenshot of the report output of the content item page after clicking the print button

·     Step-by-Step Guide to develop the above mentioned XMLP Report

o   Create a PSQuery which will list the content item information as displayed on page.

o   Create a Data Source of type “PS Query” using the PSQuery created in the above step

o   Under “Generate File” column you will see two links as ‘Generate’, click on both the links to generate XML and XSD files as highlighted in yellow.
o   The moment you click on Generate link, automatically XML and XSD file will be generated with a link under “File Column”.
o   Click on the first .XML file and .XSD File link to download the xml and xsd to your local machine (Use IE browser)  
o   Download and Install ‘Designer Helper’ in case not installed

o   Open Microsoft office word, click on the add-ins tab, click on the ‘Data’ and select ‘Load XML Data’, upload the XML file you have just downloaded on your local machine and ‘Load XSD Schema’ file from your local machine.
o   After loading data, you will get a confirm message ‘Data Load Successfully’.

o   Click on the ‘Insert’ tab, select Table wizard, select table then select columns which you want to show in your report and click next and finish as shown below

o   Template is ready with the fields as shown below:

o   Instead of using table wizard, you can directly drag and drop fields (use free form) in the template according to your business requirements.
o   Save the template as .RTF format
o   Create Report Definition, provide the name of your report definition
o   Select the data source id, which you have created earlier, from the prompt
o   Screenshot below for your reference

o   Upload the .rtf template you have created

o   Select output format type as PDF

                         o   Save the report definition.
o   Open application designer, write the following PeopleCode in the FieldChange Event of the Print Button. Please note in our page design we have level 0 and level 1.
o   The code consists of two parts.
      Part 1 provides all the prompt values which you have used in your PS Query as highlighted.
      Part 2 runs the XMLP Report using the class in PeopleSoft delivered Application Package
o   Provide the report definition and template id which you have created earlier as highlighted below:

===================PS Query code for XMLP Report=================

/* Include Application Package – Used for setting output format and process report */
/* Declare delivered functions for specific tasks like setting up directory path, file extension etc  */
Declare Function DeleteLocalFile PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Declare Function GetDirSeparator PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Declare Function GetFileNameFromPath PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Declare Function GetDirectoryFromPath PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;
Declare Function GetFileExtension PeopleCode PSXPFUNCLIB.FUNCLIB FieldFormula;

/* Declare variables */
Local PSXP_RPTDEFNMANAGER:ReportDefn &oRptDefn;
Local string &sDataDir;                       /* Data directory name*/
Local string &sDirSep;                         /* Directory separator */                  
Local string &sRptDefn;                      /* Contain report definition id */
Local string &sTemplateId;                 /* Contain template Id */
Local string &sOutputFile;                  /* Output file name  */
Local date &dAsOfDate;                     /* Date of running report */
Local string &sOutputFormat, &sFileExt;                         /*  Report output format and File extension */
Local Record &rcdQryPrompts;                        /* PS Query prompt record */
Local string &sOutputDir, &RptOutputDir;      /* Output directory and Report repository */

/* Try catch block starts */
/* Provide report definition id*/
   &sRptDefn = "DK_CONTENT";
/*Provide template id defined in the report definition */
   &sTemplateId = " DK_CONTENT_1";
/* Current Date of execution*/
   &dAsOfDate = %Date;
   /* detect system directory separator */
   &sDirSep = GetDirSeparator();
   /* this method will create process directory in PSHOME server */
   CreateDirectory("XMLP", %FilePath_Relative);
   /* start logging for debugging purpose */
   WriteToLog(%ApplicationLogFence_Level1, "*** XML Publisher View Report Job Start: " | String(%Datetime) | "***");
   WriteToLog(%ApplicationLogFence_Level1, "Report Name = " | &sRptDefn);
   WriteToLog(%ApplicationLogFence_Level1, "Template id = " | &sTemplateId);
   WriteToLog(%ApplicationLogFence_Level1, "As of Date = " | &dAsOfDate);
   WriteToLog(%ApplicationLogFence_Level1, "Output Format = " | &sOutputFormat);
   WriteToLog(%ApplicationLogFence_Level1, "Language Code = " | %Language_User);
   /* instantiate report definition object and pass report definition id  */
   &oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&sRptDefn);
   /* output directory – after running the report the pdf output will be generated in the report repository */
   &RptOutputDir = GetEnv("PS_SERVDIR") | &sDirSep | "files" | &sDirSep | "XMLP" | &sDirSep | UuidGen();
   &sOutputDir = &RptOutputDir | &sDirSep | "RptInst";
   &sDataDir = &RptOutputDir | &sDirSep | "Data";
   CreateDirectory(&sOutputDir, %FilePath_Absolute);
   CreateDirectory(&sDataDir, %FilePath_Absolute);
   &oRptDefn.OutDestination = &RptOutputDir;
   /* select Output format in PDF specified as function parameter ‘2’ */
  /* 2 - PDF */
  /* 5 - HTM */
  /* 8 - XLS */
  /* 12 - RTF */
&sOutputFormat = &oRptDefn.GetOutDestFormatString(Value("2"));
   /* fill PS Query prompt record with values */
   &rcdQryPrompts = &oRptDefn.GetPSQueryPromptRecord();
   If Not &rcdQryPrompts = Null Then
 &rcdQryPrompts.JPM_CAT_TYPE.Value = JPM_CAT_ITEMS.JPM_CAT_TYPE.Value;
                /* Set all the prompt values in the PS Query  */
       /* Call process report function with template id, language, current date and output format in PDF  as function parameters */
   &oRptDefn.ProcessReport(&sTemplateId, %Language_User, &dAsOfDate, &sOutputFormat);
 /* Set file extension like PDF, HTM, XLS or RTF */
  &sFileExt = GetFileExtension(&sOutputFormat);
   /* Display the output  method will fetch the report from report repository and open the report it in a new browser */
   /* cleanup cache */
   DeleteLocalFile(&sOutputFile, %FilePath_Absolute);
   WriteToLog(%ApplicationLogFence_Level1, "*** XML Publisher View Report Job End: " | String(%Datetime) | "***");
/* Catch block starts */
catch Exception &Err
   Local string &sSub1, &sSub2, &sSub3, &sSub4, &sSub5;
   Evaluate &Err.SubstitutionCount
   When > 4
      &sSub5 = &Err.GetSubstitution(5);
   When > 3
      &sSub4 = &Err.GetSubstitution(4);
   When > 2
      &sSub3 = &Err.GetSubstitution(3);
   When > 1
      &sSub2 = &Err.GetSubstitution(2);
   When > 0
      &sSub1 = &Err.GetSubstitution(1);
   Error MsgGet(&Err.MessageSetNumber, &Err.MessageNumber, &Err.ToString(), &sSub1, &sSub2, &sSub3, &sSub4, &sSub5);
/* End of Code */


  • This code will only work with the PS Query data source.
  • This code will not work for the report which fetches data directly from the page buffer instead from physical database record.
Contributed by Rohit

No comments:

Post a Comment