Friday, September 10, 2010

XML Publisher Part 2

I hope you enjoy the first part XML Publisher Part 1!!! This time we will bring XML Publisher one step up. We will use Application Engine, PeopleCode and XMLP together to produce a nice looking batch report. The concept are like SQR, retrieving data from database via SQL SELECT, formating data and displaying data to a report usually in the form of PDF, CSV, etc. 

In order to retrieve data using PeopleCode you need to populate a rowset. 
import PSXP_XMLGEN:*;

/*Create Rowset*/
&rs = CreateRowset(Record.PERSONAl_DATA);

You need to fill this rowset with data by doing this;

/*Fill Rowset*/
&rs.FILL("WHERE FILL.EMPLID LIKE 'EID000%'");

You'll notice that I have an import statement on top. That is an delivered Application Package, inside that package are methods that we will use in our code.

We will now create our Sample Data File and Schema File by running the code above and the code below.

/*Create Schema*/
&rds = create PSXP_XMLGEN:RowSetDS(); /*example package method*/
&mySchema = &rds.GetXSDSchema(&rs);
&f1 = GetFile("c:\temp\JOB_XSD.xsd""W"%FilePath_Absolute);
&f1.WriteLine(&mySchema);
&f1.Close();

/*Create Sample XML File*/
&myXMLFile = &rds.GetXMLData(&rs, "c:\temp\JOB_XSD.xsd");
&f2 = GetFile("c:\temp\JOB_XML.xml""W"%FilePath_Absolute);
&f2.WriteLine(&myXMLFile);
&f2.Close();


This code will generate two files, an schema file with extension .xsd and sample data file with extension .xml. You need to upload the files in the report category page within PeopleSoft, create Data Source Definition (apply the things you learned from Part 1) choose Rowset data source type instead of PS Query. Also create the Report Definition and Process definition. Add few more lines to the Peoplecode and you will able to run and produce report. Your code should look like this;


import PSXP_RPTDEFNMANAGER:*;
import PSXP_XMLGEN:*;

&sRptDefn = "JOB_DEFN";
&sTemplateId = "JOB_TEMP";
&sLangCode = "";
&dtAsOfDate = %Date;
&sOutputFmt = "PDF";
&RptOutputDir = "c:\temp\" "XMLP";

&ReportDef.OutDestination = &RptOutputDir;

/*Set-Up Report*/
&ReportDef = create PSXP_RPTDEFNMANAGER:ReportDefn(&sRptDefn);
&ReportDef.Get();

/*Create Rowset*/
&rs = CreateRowset(Record.PERSONAl_DATA);


/*Fill Rowset*/&rs.FILL("WHERE FILL.EMPLID LIKE 'EID000%'");

/*Create Schema*/
&rds = create PSXP_XMLGEN:RowSetDS(); /*package method*/
&mySchema = &rds.GetXSDSchema(&rs);
&f1 = GetFile("c:\temp\JOB_XSD.xsd""W"%FilePath_Absolute);
&f1.WriteLine(&mySchema);
&f1.Close();


/*Create Sample XML File*/
&myXMLFile = &rds.GetXMLData(&rs, "c:\temp\JOB_XSD.xsd");
&f2 = GetFile("c:\temp\JOB_XML.xml""W"%FilePath_Absolute);
&f2.WriteLine(&myXMLFile);
&f2.Close();


/* output format */
&sOutputFormat = &sOutputFmt;

/*Provide a Data Source for the Report*/
&ReportDef.SetRuntimeDataRowset(&rs);

/*Generate the Report*/
&ReportDef.ProcessReport(&sTemplateId, %Language_User%Date, &sOutputFormat);

/*Publish the Report*/
&ReportDef.Publish("", &RptOutputDir, "XMLP", JOB_AET.PROCESS_INSTANCE);
&sFileExt = GetFileExtension(&sOutputFormat);

No comments:

Post a Comment