Retrieving Document Data
This section discusses and provides code examples for how to:
-
Retrieve document data from the Message object.
-
Retrieve document data from message segments.
-
Retrieve document data within a Notification event using message segments
Retrieving Document Data from the Message Object
The following code provides an example of how to retrieve a document from the Message object:
Local Message &MSG;
Local Document &DOC;
Local Primitive &PRIM;
Local Compound &COM, &COM_ID, &COM_BILL, &COM_SHIP, &COM_ITEM;
Local Collection &COL_ITEM;
&MSG = CreateMessage(Operation.PURCHASE_ORDER);
&DOC = &MSG.GetDocument();
&COM = &DOC.DocumentElement;
&COM.GetPropertyByName("LanguageCode").Value = "ENG";
/* Populate TransactionID Compound */
&COM_ID = &COM.GetPropertyByName("TransactionId");
&COM2.GetPropertyByIndex(1).value = "KAC";
&COM2.GetPropertyByIndex(1).value = "12345678";
/* Populate BillTo Compound */
&COM_BILL = &COM.GetPropertyByName("BillTo");
&COM5.GetPropertyByName("name").Value = "RobbyNash";
&COM5.GetPropertyByName("number").Value = 713;
&COM5.GetPropertyByName("street").Value = "High Wind";
&COM5.GetPropertyByName("unit").Value = "";
&COM5.GetPropertyByName("city").Value = "Paia";
&COM5.GetPropertyByName("state").Value = "Maui HI";
&COM5.GetPropertyByName("zipcode").Value = "96779";
/* Populate item_collection Collection (2 rows) */
&COL_ITEM = &COM.GetPropertyByName("item_collection");
&COM_ITEM = &COL_ITEM.CreateItem();
&PRIM = &COM_ITEM.GetPropertyByName("item");
&PRIM.Value = "mast";
&PRIM = &COM_ITEM.GetPropertyByName("sku");
&PRIM.Value = "123322";
&PRIM = &COM_ITEM.GetPropertyByName("price");
&PRIM.Value = 300;
&PRIM = &COM_ITEM.GetPropertyByName("quantity");
&PRIM.Value = 12;
&nRet = &COL_ITEM.AppendItem(&COM_ITEM);
&COM_ITEM = &COL_ITEM.CreateItem();
&COM5.GetPropertyByName("item").Value = "boom";
&COM5.GetPropertyByName("sku").Value = "123334";
&COM5.GetPropertyByName("price").Value = 270;
&COM5.GetPropertyByName("quantity").Value = 10;
&nRet = &COL_ITEM.AppendItem(&COM_ITEM);
%IntBroker.Publish(&MSG);
Retrieving Document Data from Message Segments
The following code example shows an example of retrieving document data from message segments. As discussed elsewhere in this section, the example shows setting the following statement to NULL :
&DOC = Null;
Setting the statement to NULL clears memory between segment loops:
import PS_PT:Integration:INotificationHandler;
class DOCUMENT_TESTER implements PS_PT:Integration:INotificationHandler
method FLIGHTDATA();
method OnNotify(&MSG As Message);
end-class;
/* constructor */
method FLIGHTDATA
end-method;
method OnNotify
/+ &MSG as Message +/
/+ Extends/implements PS_PT:Integration:INotificationHandler.OnNotify +/
/* Variable Declaration */
Local Rowset &rs;
Local Document &DOC;
Local Record &FLIGHTDATA, &REC;
Local integer &i;
/* get each segment of data via a Document and proces it */
For &i = 1 To &MSG.SegmentCount
/* null out object to release memory */
&DOC = Null;
&MSG.GetSegment(&i);
/* pass true to GetDocument method to take ownership of object */&DOC = &MSG.GetDocument( True);
/* process Document data for each segment */
End-For;
end-method;
Retrieving Document Data within a Notification Event Using Message Segments
The following code example demonstrates how to retrieve document data within an Notification event using message segments.
As discussed elsewhere in this section, the example shows setting the following statement to NULL :
&DOC = Null;
Setting the statement to NULL clears memory between segment loops:
For &i = 1 To &MSG.SegmentCount
&DOC = Null;
&MSG.GetSegment(&i);
&DOC = &MSG.GetDocument();
&COM = &DOC.DocumentElement;
&str = &COM.GetPropertyByName("LanguageCode").Value;
&COM_ID = &COM.GetPropertyByName("TransactionId");
&str = &COM_ID.GetPropertyByIndex(2).Value;
&COM_BILL = &COM.GetPropertyByName("BillTo").Value;
&str = &COM_BILL.GetPropertyByName("name").Value;
&COL_ITEM = &COM.GetPropertyByName("item_collecion");
For &j = 1 To &COL_ITEM.count
&COM_ITEM = &COL_ITEM.GetItem(&j);
&str = &COM_ITEM.GetPropertyByName("item").Value;
End-For;
End-For;