Thursday, December 18th, 2008

PeopleSoft export to formatted MS Word file using XML templates

You don’t need a program like Oracle XML Publisher to present a PeopleSoft user a formatted MS Word file, filled with PeopleSoft data. If you want to export PeopleSoft data to a formatted MS Word file, just follow these few simple steps:

  1. create a formatted xml file in MS Word containing placeholders for the PeopleSoft data. Store this xml in the database.
  2. Create a page containing an export button, which calls an IScript
  3. Create an IScript which retrieves the template from the database, fetches the data to be inserted from the database and substitutes the placeholders for the data.

In detail:

  1. Open MS Word and create and format a page normally. Create placeholders that will contain the data from the database or PeopleCode. For example {NAME}. Be sure to save the file as an XML document. We want to store the plain text “source” of the formatted XML document in the database. For this reason open the file in a plain text editor like Notepad. You can check your placeholder(s) here. Copy the contents and save them in the database. This can be in a custom table or perhaps in the message catalog. In this example we’ll use the message catalog 20.000 and item 1.
  2. Create a page in Application Designer and insert a button or hyperlink. The destination of the button is a PeopleCode command of a field in a derived record. For example DERIVED_REC.CALL_ISCRIPT. In the FieldChange event of the above mentioned field, call the ViewURL(URL_str) function. The parameter of this function is an IScript which we’ll create in the next step.
  3. Example:

    &sUrl = %Request.RequestURI | “?ICType=Script&ICScriptProgramName=DERIVED_REC.CALL_ISCRIPT.FieldFormula.ISCRIPT_XML_RESPONSE”;

    ViewURL(&sUrl);

    In newer versions you can use functions like GenerateScriptContentURL to compose the IScript URL.

  4. Create an IScript with the following content:

Function ISCRIPT_XML_RESPONSE

/* set filename */

&XMLFileName = “xml_export”;

/* set headers so the browser sends a save dialog box */

&contDisposition = “attachment; filename=” | &XMLFileName | “.doc”;

%Response.SetHeader(“content-disposition”, &contDisposition);

/* set content type to word, so MS Word can be opened */

%Response.SetContentType(“application/msword”);

/* get the template xml file */

&sXMLTpl = MsgGetExplainText(20000, 1, “XML not found”);

/* get the data */

&sName = “John Doe”;

/* substitute placeholder for the data */

&sXMLTpl = Substitute(&sXMLTpl, “{NAME}”, &sName);

/* send to browser */

%Response.Write(&sXMLTpl);

End-Function;

A couple of notes:

  • Because we are using an IScript we can’t access the component buffer data. So if you want to use content specific variables in your IScript, create some global variables in step 2 which can be addressed in the IScript.
  • Don’t forget to add the IScript to the weblibrary of your permission list.
  • When creating the xml template, turn off any spelling or grammar checks for this can disturb the xml placeholders.
  • When you’ve made an error in a placeholder, completely retype the placeholder. A partial correction can disturb the xml.

 

 Viewed 12073 times by 2999 visitors


Category: General / Technical
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses (last comment shown first)

October 14, 2009
JC
JC

This approach is not working for me. I am trying to do it inside LSv9.0

Details: When I click on the component link’Generate Report’ it takes me back to the search page.

Any idea?

[Reply to this comment]

Rick van Breugel

Rick van Breugel Reply:

In my post the PeopleCode of the link (in your case the Generate Report link) was:

&sUrl = %Request.RequestURI | “?ICType=Script&ICScriptProgramName=DERIVED_REC.CALL_ISCRIPT.FieldFormula.ISCRIPT_XML_RESPONSE”;
ViewURL(&sUrl);

According to PeoleBooks, all iScripts must be contained in records named WEBLIB_xxx. So the correct PeopleCode should be:

&sUrl = %Request.RequestURI | “?ICType=Script&ICScriptProgramName=WEBLIB_REC.CALL_ISCRIPT.FieldFormula.ISCRIPT_XML_RESPONSE”;
ViewURL(&sUrl);

Hope this helps.

[Reply to this comment]


July 2, 2009
David
David

Hi,

Please send the Peoplesoft XMLP documention. along with Sample examples.

Thanks,
Sridhara Raju

[Reply to this comment]