PsoftToXML Application Class - Convert PeopleSoft Object to XML

By Chris Malek | Fri, Oct 27, 2017

I want to release some code that may be helpful for PeopleSoft web service developers providing PeopleSoft data to 3rd parties. This would be a replacement for using Rowset-based messages.

Introduction

If you provide XML web services from PeopleSoft to other systems, one of the major decisions you have to make is to how to encode the XML. You have a few options to return data to the client.

  • Use the PeopleCode XML class to create some bespoke XML document.
    • If your client needs a specific XML document structure then you will have use the XML application class that returns the specific structure they require.
  • Use Rowset-based message objects and let PeopleSoft handle the encoding.
    • If you are using Rowset-based you end up returning all or some of the fields. The XML structure is tightly coupled to the record structures. If your client can handle the PeopleSoft data structure then Rowset-based messages are a good solution.

I have used both of these methods for many years. They both have their place.

I developed some code that will serve a similar purpose to the rowset-based messages. It is a “PeopleSoft Object to XML encoder” called psoftToXML. It gives you some flexibility over rowset-based message objects in organizing the output. It also allows you to provide dynamic content where a rowset-based message is tied to a specific record. So if you have a common piece of handler code serving different data based on the inputs this could be helpful.

I wrote this because I was providing a bunch of data to a 3rd party system and that system could handle the raw PeopleSoft data structure. I did not want to maintain a bunch of rowset-based messages every time I wanted to add a new table to the export.

Class Signature and Import

First let’s just take a quick look at the class definition. There are a few methods to take note of.

  • RowsetToXML - Encodes a rowset object and all it’s child rows and rowsets into XML under some XML parentNode.
  • RowToXML - Encodes a row object and all it’s child records into XML under some XML parentNode.
  • RecordToXML - Encodes a record object and all it’s fileds into XML under some XML parentNode.
class psoftToXML
   method RowsetToXML(&parentNode As XmlNode, &rowSetIn As Rowset) Returns XmlNode;
   method RecordToXML(&parentNode As XmlNode, &recordIn As Record) Returns XmlNode;
   method FieldToXML(&ParentNode As XmlNode, &fieldIn As Field) Returns XmlNode;
   method RowToXML(&ParentNode As XmlNode, &rowIn As Row) Returns XmlNode;
   method psoftToXML();
   property array of string fieldsToSkip;
end-class;

You import the class like this:

import CHG_XML:psoftToXML;

Example Usage

Let’s take a look at some example use cases and the output that is generated. These PeopleCode examples are snippets of a web service handler that is accepting input, pulling data from the database and then returning the PeopleSoft record/rowset objects. If you need a full example of the web service handler please see A Complete PeopleSoft REST Web Service Example.

Example 1 - Return Person Rowset

In this example, we will encode a rowset with just the PERSON record filled for one person. The code sets up a base XML document then uses the RowsetToXML to append the encoded rowset to the XML.

&response = CreateMessage(Operation.CHG_PERSON_GET, %IntBroker_Response);

Local CHG_XML:psoftToXML &p2XML = create CHG_XML:psoftToXML();

Local XmlDoc &xmlout;
Local XmlNode &childNode;

&xmlout = CreateXmlDoc("<?xml version='1.0'?><response/>");

Local Rowset &rsPerson = CreateRowset(Record.PERSON);

&rsPerson.Fill("WHERE EMPLID = :1 ", &paramEMPLID);
&childNode = &p2XML.RowsetToXML(&xmlout.DocumentElement, &rsPerson);

&response.SetXmlDoc(&xmlout);

That one call to RowsetToXML outputs the following XML which is an XML encoded representation of the rowset object. It includes all rows, records and fields. In this case there is just one row and one record.

<?xml version="1.0"?>
<response>
    <PERSON PSOBJECTTYPE="ROWSET">
        <ROW PSOBJECTTYPE="ROW" RowNumber="1">
            <PERSON PSOBJECTTYPE="RECORD">
                <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                <BIRTHDATE PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1950-04-01</BIRTHDATE>
                <BIRTHPLACE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                <BIRTHCOUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</BIRTHCOUNTRY>
                <BIRTHSTATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                <DT_OF_DEATH PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD"/>
                <LAST_CHILD_UPDDTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2009-04-14-10.26.08.000000</LAST_CHILD_UPDDTM>
            </PERSON>
        </ROW>
    </PERSON>
</response>

Example 2 - Encode Person Record

You can also just include one record object. Here is a sample PeopleCode call for a person object.

Local Record &recPerson = CreateRecord(Record.PERSON);
&recPerson.EMPLID.Value = &paramEMPLID;
&recPerson.SelectByKey();
      
&childNode = &p2XML.RecordToXML(&xmlout.DocumentElement, &recPerson);

The output is the following.

<?xml version="1.0"?>
<response>
    <PERSON PSOBJECTTYPE="RECORD">
        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
        <BIRTHDATE PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1950-04-01</BIRTHDATE>
        <BIRTHPLACE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
        <BIRTHCOUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</BIRTHCOUNTRY>
        <BIRTHSTATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
        <DT_OF_DEATH PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD"/>
        <LAST_CHILD_UPDDTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2009-04-14-10.26.08.000000</LAST_CHILD_UPDDTM>
    </PERSON>
</response>

Example 3 - Nested Rowsets

The RowsetToXML method will also find any child rowsets and encode those recursively. In this example, we create a nested hierarchy in memory of the PERSON -> ADDRESSES hierarchy and fill the person data and all addresses for an EMPLID. Any number of child rowsets can be added.

Local Rowset &rsPerson2 = CreateRowset(Record.PERSON, CreateRowset(Record.ADDRESSES));
&rsPerson2.Fill("WHERE EMPLID = :1 ", &paramEMPLID);
&rsPerson2.GetRow(1).GetRowset(Scroll.ADDRESSES).Fill("WHERE EMPLID = :1 ", &paramEMPLID);

&childNode = &p2XML.RowsetToXML(&xmlout.DocumentElement, &rsPerson2);

The output looks like this:

<?xml version="1.0"?>
<response>
    <PERSON PSOBJECTTYPE="ROWSET">
        <ROW PSOBJECTTYPE="ROW" RowNumber="1">
            <PERSON PSOBJECTTYPE="RECORD">
                <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                <BIRTHDATE PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1950-04-01</BIRTHDATE>
                <BIRTHPLACE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                <BIRTHCOUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</BIRTHCOUNTRY>
                <BIRTHSTATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                <DT_OF_DEATH PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD"/>
                <LAST_CHILD_UPDDTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2009-04-14-10.26.08.000000</LAST_CHILD_UPDDTM>
            </PERSON>
            <ADDRESSES PSOBJECTTYPE="ROWSET">
                <ROW PSOBJECTTYPE="ROW" RowNumber="1">
                    <ADDRESSES PSOBJECTTYPE="RECORD">
                        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                        <ADDRESS_TYPE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HOME</ADDRESS_TYPE>
                        <EFFDT PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1995-12-01</EFFDT>
                        <EFF_STATUS LongTranslateValue="Active" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">A</EFF_STATUS>
                        <COUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTRY>
                        <ADDRESS1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">9706 Peridot Drive</ADDRESS1>
                        <ADDRESS2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS4 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">Reston</CITY>
                        <NUM1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <NUM2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <HOUSE_TYPE LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD1 LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <COUNTY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTY>
                        <STATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">VA</STATE>
                        <POSTAL PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">20190</POSTAL>
                        <GEO_CODE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <IN_CITY_LIMIT PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS1_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS2_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <REG_REGION PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <LASTUPDDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">1900-01-01-00.00.00.000000</LASTUPDDTTM>
                        <LASTUPDOPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                    </ADDRESSES>
                </ROW>
                <ROW PSOBJECTTYPE="ROW" RowNumber="2">
                    <ADDRESSES PSOBJECTTYPE="RECORD">
                        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                        <ADDRESS_TYPE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HOME</ADDRESS_TYPE>
                        <EFFDT PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1997-10-01</EFFDT>
                        <EFF_STATUS LongTranslateValue="Active" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">A</EFF_STATUS>
                        <COUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTRY>
                        <ADDRESS1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">9706 Peridot Drive</ADDRESS1>
                        <ADDRESS2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS4 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">Reston</CITY>
                        <NUM1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <NUM2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <HOUSE_TYPE LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD1 LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <COUNTY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTY>
                        <STATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">VA</STATE>
                        <POSTAL PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">20190</POSTAL>
                        <GEO_CODE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <IN_CITY_LIMIT PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS1_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS2_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <REG_REGION PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <LASTUPDDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">1900-01-01-00.00.00.000000</LASTUPDDTTM>
                        <LASTUPDOPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                    </ADDRESSES>
                </ROW>
                <ROW PSOBJECTTYPE="ROW" RowNumber="3">
                    <ADDRESSES PSOBJECTTYPE="RECORD">
                        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                        <ADDRESS_TYPE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HOME</ADDRESS_TYPE>
                        <EFFDT PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">2000-01-16</EFFDT>
                        <EFF_STATUS LongTranslateValue="Active" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">A</EFF_STATUS>
                        <COUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTRY>
                        <ADDRESS1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">9706 Peridot Drive</ADDRESS1>
                        <ADDRESS2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS4 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">Reston</CITY>
                        <NUM1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <NUM2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <HOUSE_TYPE LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD1 LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <COUNTY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTY>
                        <STATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">VA</STATE>
                        <POSTAL PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">20190</POSTAL>
                        <GEO_CODE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <IN_CITY_LIMIT PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS1_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS2_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <REG_REGION PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <LASTUPDDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">1900-01-01-00.00.00.000000</LASTUPDDTTM>
                        <LASTUPDOPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                    </ADDRESSES>
                </ROW>
                <ROW PSOBJECTTYPE="ROW" RowNumber="4">
                    <ADDRESSES PSOBJECTTYPE="RECORD">
                        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                        <ADDRESS_TYPE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HOME</ADDRESS_TYPE>
                        <EFFDT PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">2009-01-01</EFFDT>
                        <EFF_STATUS LongTranslateValue="Active" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">A</EFF_STATUS>
                        <COUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTRY>
                        <ADDRESS1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">9706 Peridot Drive</ADDRESS1>
                        <ADDRESS2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS4 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">Reston</CITY>
                        <NUM1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <NUM2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <HOUSE_TYPE LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD1 LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <COUNTY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTY>
                        <STATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">VA</STATE>
                        <POSTAL PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">20190</POSTAL>
                        <GEO_CODE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <IN_CITY_LIMIT PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS1_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS2_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <REG_REGION PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <LASTUPDDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2009-04-14-10.26.03.000000</LASTUPDDTTM>
                        <LASTUPDOPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">SMPLFED</LASTUPDOPRID>
                    </ADDRESSES>
                </ROW>
                <ROW PSOBJECTTYPE="ROW" RowNumber="5">
                    <ADDRESSES PSOBJECTTYPE="RECORD">
                        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
                        <ADDRESS_TYPE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">MAIL</ADDRESS_TYPE>
                        <EFFDT PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">2000-01-16</EFFDT>
                        <EFF_STATUS LongTranslateValue="Active" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">A</EFF_STATUS>
                        <COUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</COUNTRY>
                        <ADDRESS1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">ADDRESS1</ADDRESS1>
                        <ADDRESS2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">ADDRESS2</ADDRESS2>
                        <ADDRESS3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">ADDRESS3</ADDRESS3>
                        <ADDRESS4 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">ADDRESS4</ADDRESS4>
                        <CITY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <NUM1 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <NUM2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <HOUSE_TYPE LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD1 LongTranslateValue="" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDR_FIELD3 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <COUNTY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <STATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <POSTAL PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <GEO_CODE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <IN_CITY_LIMIT PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS1_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS2_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <ADDRESS3_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <CITY_AC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <REG_REGION PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                        <LASTUPDDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD"/>
                        <LASTUPDOPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
                    </ADDRESSES>
                </ROW>
            </ADDRESSES>
        </ROW>
    </PERSON>
</response>

Example 4 - Excluding Fields

You can also exclude fields by pushing to an array on the class of the fields you do not want to write. These are fields that could be sensitive or you don’t want to show to a client. Here is the sample code. Here we are telling the class to not write the DT_OF_DEATH or BIRTHDATE fields.

      &p2XML.fieldsToSkip.Push("DT_OF_DEATH");
      &p2XML.fieldsToSkip.Push("BIRTHDATE");

      Local Record &recPerson4 = CreateRecord(Record.PERSON);
      &recPerson4.EMPLID.Value = &paramEMPLID;
      &recPerson4.SelectByKey();
      &childNode = &p2XML.RecordToXML(&xmlout.DocumentElement, &recPerson4);

You will see in the output that those fields are not included.


<?xml version="1.0"?>
<response>
    <PERSON PSOBJECTTYPE="RECORD">
        <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">L00013</EMPLID>
        <BIRTHDATE PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1950-04-01</BIRTHDATE>
        <BIRTHPLACE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
        <BIRTHCOUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</BIRTHCOUNTRY>
        <BIRTHSTATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
        <LAST_CHILD_UPDDTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2009-04-14-10.26.08.000000</LAST_CHILD_UPDDTM>
    </PERSON>
</response>

Example 5 - Changing the Location in the XML.

All the encoding methods take a “xml parent node” as a parameter. This gives it a pointer to an xml tree to append to. So really you can write it anywhere. Your code can mix in free form XML elements with PeopleSoft objects. The following is an example of appending the PERSON and PSOPRDEFN records under two different XML parent nodes.

Local Record &recPerson5 = CreateRecord(Record.PERSON);
&recPerson5.EMPLID.Value = &paramEMPLID;
&recPerson5.SelectByKey();

Local XmlNode &tempNode;

&tempNode = &xmlout.DocumentElement.AddElement("PERSON_DATA");
&childNode = &p2XML.RecordToXML(&tempNode, &recPerson5);


&tempNode = &xmlout.DocumentElement.AddElement("SECURITY_DATA");
Local Record &recOPR5 = CreateRecord(Record.PSOPRDEFN);
SQLExec("%selectall(:1) WHERE PSOPRDEFN.EMPLID = :2", &recOPR5, &paramEMPLID, &recOPR5);
&childNode = &p2XML.RecordToXML(&tempNode, &recOPR5);

<?xml version="1.0"?>
<response>
    <PERSON_DATA>
        <PERSON PSOBJECTTYPE="RECORD">
            <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">PN001</EMPLID>
            <BIRTHDATE PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">1961-01-01</BIRTHDATE>
            <BIRTHPLACE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
            <BIRTHCOUNTRY PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USA</BIRTHCOUNTRY>
            <BIRTHSTATE PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">FL</BIRTHSTATE>
            <DT_OF_DEATH PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD"/>
            <LAST_CHILD_UPDDTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2016-02-08-10.01.24.000000</LAST_CHILD_UPDDTM>
        </PERSON>
    </PERSON_DATA>
    <SECURITY_DATA>
        <PSOPRDEFN PSOBJECTTYPE="RECORD">
            <OPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">AJORDAN</OPRID>
            <USERIDALIAS PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
            <VERSION PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">2911</VERSION>
            <OPRDEFNDESC PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">Alic Jordan</OPRDEFNDESC>
            <EMPLID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">PN001</EMPLID>
            <EMAILID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
            <OPRCLASS PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HCPPPCNSI</OPRCLASS>
            <ROWSECCLASS PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HCDPPCNSI</ROWSECCLASS>
            <OPERPSWD PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD"/>
            <PTOPERPSWDV2 PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">{3}aWD90N60xnjv0AFEwYkzs3no7ZilPvQvBJEgJXupXjc=</PTOPERPSWDV2>
            <OPERPSWDSALT PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">uq6icV4d0KaKPCvcyENZaw==</OPERPSWDSALT>
            <ENCRYPTED PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">1</ENCRYPTED>
            <SYMBOLICID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">SYSADM1</SYMBOLICID>
            <LANGUAGE_CD LongTranslateValue="English" PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">ENG</LANGUAGE_CD>
            <MULTILANG PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">0</MULTILANG>
            <CURRENCY_CD PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">USD</CURRENCY_CD>
            <LASTPSWDCHANGE PSFIELDTYPE="DATE" PSOBJECTTYPE="FIELD">2017-07-18</LASTPSWDCHANGE>
            <ACCTLOCK PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">1</ACCTLOCK>
            <PRCSPRFLCLS PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HCSPPRFL</PRCSPRFLCLS>
            <DEFAULTNAVHP PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">HCSPNAVHP</DEFAULTNAVHP>
            <FAILEDLOGINS PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">0</FAILEDLOGINS>
            <EXPENT PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">0</EXPENT>
            <OPRTYPE PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">0</OPRTYPE>
            <LASTSIGNONDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD"/>
            <LASTUPDDTTM PSFIELDTYPE="DATETIME" PSOBJECTTYPE="FIELD">2017-06-30-20.51.08.000000</LASTUPDDTTM>
            <LASTUPDOPRID PSFIELDTYPE="CHAR" PSOBJECTTYPE="FIELD">PPLSOFT</LASTUPDOPRID>
            <PTALLOWSWITCHUSER PSFIELDTYPE="NUMBER" PSOBJECTTYPE="FIELD">0</PTALLOWSWITCHUSER>
        </PSOPRDEFN>
    </SECURITY_DATA>
</response>

Getting The code

You can grab the PeopleSoft project on the github page psoftToXML

Article Categories