Thursday, September 9, 2010

Publish/Generate an XML Report from a link in a PIA

We can generate XML report from a Link in PIA. Click a given link in PIA and your desired report will pop-up. Follow the below given steps:
1. Prepare a Query
2. Define XML Data Source and Report Definition.
3. Write the following code in relevant Event of peoplecode.

import JPM_PROFILES_MANAGER:CMP_PROFILE:BUS:ProfileIdentityController;
import HCR_JPM_PKG:Utilities:TextCatalog;
import PSXP_RPTDEFNMANAGER:*;
import HCR_JPM_PKG:Profiles:BUS:Profile;
Local Record &promptRec;
/********************************************************************************
* Function DeleteLocalFile
* deletes appserver local file
********************************************************************************/
Function DeleteLocalFile(&sFilename As string, &nPathType As number)
Local File &oFile;
try
If &sFilename <> "" And
FileExists(&sFilename, &nPathType) Then
&oFile = GetFile(&sFilename, "R", &nPathType);
If &oFile.IsOpen Then
&oFile.Delete();
End-If;
End-If;
catch Exception &Dummy
end-try;
End-Function;
Function Personal_Details_Change_Report(&TemplateID);
/*REPORT ON DEMAND*/
Local PSXP_RPTDEFNMANAGER:ReportDefn &oRptDefn;
Local PSXP_RPTDEFNMANAGER:Utility &oUtil;
Local HCR_JPM_PKG:Profiles:BUS:Profile &oProfile;
Local string &sRptDefn, &sTemplateId, &sProfile_id, &sReportname;
Local string &sOutFileName, &sOutputFile, &sOprid;
Local string &RUNREPORT;
Local date &dAsOfDate;
Local string &sOutputFormat;
Local number &OutDestFormat;
/* high level variables*/
&RUNREPORT = "Y";
&dAsOfDate = &inAsOfDate;
&OutDestFormat = 0; /*0=Default 2=PDF 5=HTML 8=XLS 12=RTF*/
&sOprid = %OperatorId;
&sReportname = "HM_AWF_WAB02";
&sTemplateId = &TemplateID;
try
/* create report defn object */
&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn(&sReportname);
&oRptDefn.Get();
/* Get the PSQuery prompt record to setup the keys */
&promptRec = &oRptDefn.GetPSQueryPromptRecord();
&promptRec.GetField(Field.EMPLID).Value = %EmployeeId;
&oRptDefn.SetPSQueryPromptRecord(&promptRec);
/* output format */
If &OutDestFormat = 0 Then
&sOutputFormat = " "
Else
&sOutputFormat = &oRptDefn.GetOutDestFormatString(&OutDestFormat);
End-If;
/*generate the report*/
&oRptDefn.ProcessReport(&sTemplateId, %Language_Data, &dAsOfDate, &sOutputFormat);
CommitWork();
/* display the output */
&oRptDefn.DisplayOutput();
/* cleanup */
DeleteLocalFile(&sOutputFile, %FilePath_Absolute);
REM WriteToLog(%ApplicationLogFence_Level1, "*** XML Publisher View Report Job End: " | String(%Datetime) | "***");
end-try;
End-Function;

Note: We can give dynamic input parameters to the Query also. The following peace of code is used in the above example to realize the dynamic assignment of input parameters.

&promptRec = &oRptDefn.GetPSQueryPromptRecord();
&promptRec.GetField(Field.EMPLID).Value = %EmployeeId;

1 comment:

  1. Have you generated an XML report using Rowset as the datasource instead of PSQuery and if yes can you share us the sample peoplecode ???

    ReplyDelete