Wednesday, June 6, 2012

XML Publisher reports from PeopleCode

Steps to create an XML Publisher report using People Code

Prepare XML File
  • Instantiate a new File object and associate it with a local xml file.
  • Create a local Rowset and fill it with the data needed for report.
  • Open the xml file and set the File Layout (XML) to the file.
  • Write the data from Rowset to the xml file and close it.
Generate Report using the XML File
  • Import Report definition manager Application classes.
  • Create a new report definition object using the XML Publisher Report ID.
  • Call the Process Request method using the Template ID.
  • Display the generated output report.

XML File Generation Sample:
&file_name = "xmlReport.xml";
Local File &File = GetFile(&file_name, "W", %FilePath_Relative);
WriteToLog(%ApplicationLogFence_Error, "View XML Publisher Report");

&RS = CreateRowset(Record.MYPS_XML_TEST);
&Rows = &RS.Fill();

&File.Open(&file_name, "A", "UTF8", %FilePath_Absolute);
If &File.IsOpen Then
   &File.WriteLine("<MYPS_XML_REPORT>");
   If &File.SetFileLayout(FileLayout.MYPS_XML_TEST) Then
      &File.WriteRowset(&RS, True);
   End-If;
End-If;
&File.WriteLine("</MYPS_XML_REPORT>");
&File.Close();
Report File Generation Sample: 
import PSXP_RPTDEFNMANAGER:ReportDefn;
import PSXP_RPTDEFNMANAGER:Utility; 

Local PSXP_RPTDEFNMANAGER:ReportDefn &oPrtDefn;
Local string &ReportId = "MYPS_RPTST";
Local string &TemplateId = "MYPS_RPTST";

&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&ReportId);
&oRptDefn.Get();
&oRptDefn.SetRuntimeDataXMLFile(&file_name);
&sOutDestFormat = &oRptDefn.GetDefaultOutputFormat();
 
&oRptDefn.ProcessReport(&TemplateId, "", %Date, &sOutDestFormat);
CommitWork();

&oRptDefn.DisplayOutput();

For More info :
http://psoftdiary.blogspot.com/2012/02/xml-publisher-reports-from-peoplecode.html

No comments:

Post a Comment