Tuesday 6 December 2016

Using XML with BI Publisher

Here's a quick guide for this deadly combo:
XML, BI Publisher, and Application Engine.


We start by importing the delivered Application Package.

import PSXP_RPTDEFNMANAGER:*;

The following function is optional if you're not expecting dirty data.

Function xml_text_clean(&InputText) Returns string;
   Local string &OutputText;
   &OutputText = Substitute(&InputText, "&", "&");
   Return (&OutputText);
End-Function;

Here we are creating the xml file. Add the instance to keep the filename unique.

&Filename = %FilePath | "MYXML_" | String(MYRECORD_AET.PROCESS_INSTANCE) | ".xml";
&FILE = GetFile(&Filename, "W", %FilePath_Absolute);
If &FILE.IsOpen Then
   &FILE.WriteLine("");
   &FILE.WriteLine("");
Else
   MessageBox(0, "", 0, 0, "Error cannot open file %1", &Filename);
   Exit (0);
End-If;

Obviously, data has to come somewhere so this is the part where you do your data fetching stuff like SQLEXEC.

&ContactText = &ContactText | Char(13) | Char(10) | xml_text_clean(MYRECORD_AET.CONTACT);
&AddressText = &AddressText | xml_text_clean(MYRECORD_AET.ADDRESS);

Now assign your raw data to xml tags.

&FILE.WriteLine("<CONTACT>" | xml_text_clean(&ContactText) | "</CONTACT>");
&FILE.WriteLine("<ADDRESS>" | xml_text_clean(&AddressText) | "</ADDRESS>");

Just some regular closing stuff.

&FILE.WriteLine("");
&FILE.Close();

Start feeding the xml file to the report definition.

Local PSXP_RPTDEFNMANAGER:ReportDefn &oRptDefn;
&oRptDefn = create PSXP_RPTDEFNMANAGER:ReportDefn("MYREPORTDEFN1");
&oRptDefn.Get();
&oRptDefn.OutDestination = %FilePath;
&oRptDefn.SetRuntimeDataXMLFile(&Filename);
&oRptDefn.ProcessReport("MYREPORTDEFN1", "ENG", %Date, "PDF");

Like a good guy that we are, remove the generated XML file after we are done with it.

&FILE = GetFile(&Filename, "W", %FilePath_Absolute);
&FILE.Delete();

The report definition will look something like this.


And the report template is like this.

.

1 comment:

  1. What Does a Casino Dealer Tell You About and How Does It Work?
    What do casino gambling 양산 출장샵 mean in casinos? 공주 출장샵 and 김해 출장마사지 they are one of the oldest casinos 전주 출장마사지 in the 김제 출장마사지 world that still provide gaming.

    ReplyDelete