This chapter provides an overview of the document classes and discusses:
Data type and scope of the document classes.
Document classes built-in functions.
Document class.
DocumentKey class.
Primitive class.
Compound class.
Collection class.
A PeopleSoft document is a managed object that has two representations. The logical document depicts the document’s structure. The physical document is the rendering of the document in a specific format—either in XML or as a relational record (or records).
PeopleCode provides document classes that contain built-in functions and methods that enable you to populate data into and retrieve data from logical documents. However, you should already have knowledge of the logical document structure in order to effectively write PeopleCode to work with a specific document.
See Also
Understanding PeopleSoft Documents Technology
Every document class is its own data type—that is, documents are declared as the Document data type, primitive objects are declared as the Primitive type, and so on. For example:
Local Document &Doc;
The following are the data types of the document classes:
Document
DocumentKey
Primitive
Compound
Collection
Document objects can only be instantiated from PeopleCode. These objects can be used anywhere you have PeopleCode—that is, in Component Interface PeopleCode, record field PeopleCode, Application Engine PeopleCode, and so on.
This section provides an overview of the Document class and discusses:
Document class methods.
Document class properties.
The Document class provides the ability to manipulate a PeopleSoft document as a Document object.
In this section, the Document class methods are presented in alphabetical order.
Syntax
GenXmlString([validate])
Description
Use this method to generate an XML string representing the logical document populated with data.
Note. The Generate button on the Document Tester page uses this method to generate a test XML document.
Parameters
validate |
Specifies a Boolean value indicating whether to validate the XML document before it is generated. |
Returns
An XML string.
See Also
Generating and Viewing Test Documents
Syntax
GetDocumentKey()
Description
Use this method to generate the document keys for the document as a DocumentKey object.
Parameters
None.
Returns
A DocumentKey object.
Example
Local Document &Doc; &Doc = CreateDocument("Purchasing", "PurchaseOrder", "v1"); &DocKey = &Doc.GetDocumentKey();
See Also
Syntax
GetElement(ElementName)
Description
Use this method to retrieve a document element by name. The object returned will be a Collection, Compound, or Primitive object.
Note. Use the object’s ElementType property to determine which object type is returned.
Parameters
ElementName |
Specifies the name of the document element as a string. |
Returns
A Collection object, a Compound object, or a Primitive object.
Example
&Doc = CreateDocument(&DocKey); &DocElem = &Doc.GetElement("BillTo"); Evaluate &DocElem.ElementType When = %Document_Compound ... When = %Document_Collection ... When = %Document_Primitive ... When-Other Error ... End-Evaluate;
See Also
Syntax
GetRowset()
Description
Use this method to generate a standalone rowset for a relational-formatted document. The structure of the rowset matches the structure of the record mapped to the document. If the document is populated with data when GetRowset is called, then the rowset is populated with that data; otherwise, the rowset is empty.
Parameters
None.
Returns
A Rowset object.
Example
Local Document &Doc; Local Rowset &Doc_RS; &Doc = CreateDocument(&DocKey); &Doc_RS = &Doc.GetRowset();
See Also
Syntax
GetSchema()
Description
Use this method to generate the XML schema definition for the document.
Parameters
None.
Returns
A string containing the XML schema definition.
Example
Local Document &Doc; Local DocumentKey &DocKey; &DocKey = CreateDocumentKey("Purchasing", "PurchaseOrder", "v1"); &Doc = CreateDocument(&DocKey); &str = &Doc.GetSchema();
Syntax
ParseXmlFromFile(file_name [, validate])
Description
Use this method to generate a document from the XML schema definition provided in a file.
Parameters
file_name |
Specifies the name of the file as a string. |
validate |
Specifies a Boolean value indicating whether to validate the XML document as it is generated. |
Returns
A Boolean value: True if a document (or a valid document) was generated, False otherwise.
See Also
ParseXmlFromURL, ParseXmlString.
Syntax
ParseXmlFromURL(URL [, validate])
Description
Use this method to generate a document from the XML schema definition provided at the specified URL.
Parameters
URL |
Specifies the URL as a string. |
validate |
Specifies a Boolean value indicating whether to validate the XML document as it is generated. |
Returns
A Boolean value: True if a document (or a valid document) was generated, False otherwise.
See Also
ParseXmlFromFile, ParseXmlString.
Syntax
ParseXmlString(XML_string [, validate])
Description
Use this method to generate a document from the XML schema definition provided as an XML string.
Parameters
XML_string |
Specifies the XML as a string. |
validate |
Specifies a Boolean value indicating whether to validate the XML document as it is generated. |
Returns
A Boolean value: True if a document (or a valid document) was generated, False otherwise.
See Also
ParseXmlFromFile, ParseXmlFromURL.
Syntax
UpdateFromRowset(&Doc_RS)
Description
Use this method to update the document data with data from a stand-alone rowset.
Important! Any existing data in the document is erased and replaced by the data from the rowset.
Parameters
&Doc_RS |
Specifies the stand-alone rowset as a Rowset object. |
Returns
A Boolean value: True if the update was successful, False otherwise.
See Also
Syntax
ValidateData()
Description
Use this method to validate the data in a document.
Parameters
None.
Returns
A Boolean value: True if the document data is valid, False otherwise.
In this section, the Document class properties are presented in alphabetical order.
Description
Use this property to return the root element for this document as a Compound object.
This property is read-only.
Example
Local Document &Doc; Local DocumentKey &DocKey; Local Compount &Root /* Instatiate the Document object */ &DocKey = CreateDocumentKey("Purchasing", "PurchaseOrder", "v1"); &Doc = CreateDocument(&DocKey); &Root = &Doc.DocumentElement;
See Also
This section provides an overview of the DocumentKey class and discusses:
DocumentKey class methods.
DocumentKey class properties.
The DocumentKey class provides the ability to pass a document’s keys as a single object.
In this section, the DocumentKey class methods are presented in alphabetical order.
Syntax
SetDocumentKey(Package, DocumentName, Version)
Description
Use this method to change the document keys for a DocumentKey object.
Parameters
Package |
Specifies a document package as a string. |
DocumentName |
Specifies the name of the document as a string. Note. The document name also becomes the root element name for the document. |
Version |
Specifies the document version as a string. |
Returns
A Boolean value: True if the document keys were set successfully, False otherwise.
Example
Local Document &Doc; Local DocumentKey &DocKey; /* Instatiate the Document object */ &DocKey = CreateDocumentKey("Purchasing", "PurchaseOrder", "v1"); ... &ret = &DocKey.SetDocumentKey("Purchasing", "PurchaseOrder", "v1.1"); &Doc = CreateDocument(&DocKey);
See Also
In this section, the DocumentKey class properties are presented in alphabetical order.
Description
Use this property to return the document name from the document keys as a string.
This property is read-only.
Description
Use this property to return the package name from the document keys as a string.
This property is read-only.
Description
Use this property to return the version from the document keys as a string.
This property is read-only.
This section provides an overview of the Primitive class and discusses:
Primitive class methods.
Primitive class properties.
The Primitive class provides the ability to work with a primitive document element.
In this section, the Primitive class methods are presented in alphabetical order.
Syntax
GetEnumName(index)
Description
Use this method to return the name of the enumerated value.
Parameters
index |
Specifies the index of the enumerated value. |
Returns
A string representing the enumerated value.
See Also
Syntax
GetParent()
Description
Use this method to return the parent object of the primitive element.
Parameters
None.
Returns
A Collection object or a Compound object.
See Also
Syntax
GetPath()
Description
Use this method to return the absolute path to the primitive within the document's structure.
For example, for the Name primitive of the ShipTo compound of the PuchaseOrder document, GetPath would return the following absolute path:
PurchaseOrder/ShipTo/Name
Parameters
None.
Returns
A string representing the absolute path to the primitive.
In this section, the Primitive class properties are presented in alphabetical order.
Description
Use this property to return the type of this document element as an integer constant: %Document_Primitive,
This property is read-only.
Description
Use this property to return the number of enumerated values for this primitive element as an integer.
This property is read-only.
See Also
Description
Use this property to return a Boolean value indicating whether the value of this primitive element has been changed.
This property is read-only.
See Also
Description
Use this property to return a Boolean value indicating whether this primitive element has an initial value.
This property is read-only.
See Also
Description
Use this property return a Boolean value indicating whether this primitive element is required.
This property is read-only.
Description
Use this property to return the number of allowed spaces to the right of the decimal point as an integer.
Note. This property is available and valid for a decimal primitive type only.
This property is read-only.
See Also
MaxDefinedLength, PrimitiveType.
Description
Use this property to return the length of the primitive element as an integer.
This property is read-only.
See Also
Description
Use this property to return the name of this element as a string.
This property is read-only.
Description
Use this property to set or return the original value for this element as a string.
This property is read-write.
See Also
IsChanged, IsInitialized, Value.
Description
Use this property to return the subtype for this primitive element as an integer. Only certain primitive types have defined subtypes.
For the %Document_Integer primitive type, the values are:
Numeric Value |
Constant Value |
Description |
— |
none |
No subtype (default). |
1 |
%DocumentSubType_NonNegInteger |
Non-negative integer |
For the %Document_String and %Document_Text primitive types, the values are:
Numeric Value |
Constant Value |
Description |
— |
none |
No subtype (default). |
1 |
%DocumentSubType_AnyURI |
anyURI XML schema data type. |
5 |
%DocumentSubType_gDay |
gDay XML schema data type. |
6 |
%DocumentSubType_gMonth |
gMonth XML schema data type. |
7 |
%DocumentSubType_gYear |
gYear XML schema data type. |
8 |
%DocumentSubType_gYearMonth |
gYearMonth XML schema data type. |
2 |
%DocumentSubType_NormString |
Normalized string XML schema data type. |
4 |
%DocumentSubType_QName |
QName XML schema data type. |
3 |
%DocumentSubType_Token |
Token XML schema data type. |
This property is read-only.
See Also
Description
Use this property to return the type for this primitive element as an integer. The values are:
Numeric Value |
Constant Value |
Description |
11 |
%Document_Binary |
Binary primitive type. |
1 |
%Document_Boolean |
Boolean primitive type. |
2 |
%Document_Char |
Character primitive type. The Character primitive type allows a single-character string only. |
7 |
%Document_Date |
Date primitive type. |
9 |
%Document_DateTime |
DateTime primitive type. |
6 |
%Document_Decimal |
Decimal primitive type. |
4 |
%Document_Integer |
Integer primitive type. The Integer primitive type includes subtypes. |
3 |
%Document_String |
String primitive type. The String primitive type requires a length. The String primitive type also includes subtypes. |
10 |
%Document_Text |
Text primitive type. The Text primitive type is unbounded and does not require a length. The Text primitive type also includes subtypes. |
8 |
%Document_Time |
Time primitive type. |
This property is read-only.
See Also
Description
Use this property to return the system-assigned sequence number for this element as an integer.
This property is read-only.
Description
Use this property to set or return the value for this primitive element as a string.
This property is read-write.
See Also
IsChanged, IsInitialized, OrigValue.
This section provides an overview of the Compound class and discusses:
Compound class methods.
Compound class properties.
The Compound class provides the ability to work with a compound document element.
In this section, the Compound class methods are presented in alphabetical order.
Syntax
GetParent()
Description
Use this method to return the parent object of the compound element.
Parameters
None.
Returns
A Collection object or a Compound object.
See Also
Syntax
GetPath()
Description
Use this method to return the absolute path to the compound element within the document's structure.
For example, for the Items compound of the PuchaseOrder document, GetPath would return the following absolute path:
PurchaseOrder/Item_Collection/Items
Parameters
None.
Returns
A string representing the absolute path to the compound element.
Syntax
GetPropertyByIndex(index)
Description
Use this method to return a property of the compound element as an object.
Parameters
None.
index |
Specifies the index number of the property as an integer. |
Returns
A Collection object, a Compound object, or a Primitive object.
See Also
GetPropertyByName, PropertyCount.
Syntax
GetPropertyByName(prop_name)
Description
Use this method to return a property of the compound element as an object.
Parameters
prop_name |
Specifies the name of the property as a string. |
Returns
A Collection object, a Compound object, or a Primitive object.
See Also
Syntax
GetUniqueKey()
Description
Use this method to return the key information for this compound—that is, the package name, document name, and document version.
Parameters
None.
Returns
An array of string with three elements: package name, document name, and document version.
In this section, the Compound class properties are presented in alphabetical order.
Description
Use this property to return the type of this document element as an integer constant: %Document_Compound.
This property is read-only.
Description
Use this property to return a Boolean value indicating whether this compound element has been changed.
This property is read-only.
Description
Use this property to return a Boolean value indicating whether this compound element included initial data when the document was loaded from the XML source.
This property is read-only.
Description
Use this property return a Boolean value indicating whether this compound element is required.
This property is read-only.
Description
Use this property to return the name of this element as a string.
This property is read-only.
Description
Use this property to return the number of existing properties for this compound element as an integer.
This property is read-only.
See Also
Description
Use this property to return the system-assigned sequence number for this element as an integer.
This property is read-only.
This section provides an overview of the Collection class and discusses:
Collection class methods.
Collection class properties.
The Collection class provides the ability to work with a collection document element.
In this section, the Collection class methods are presented in alphabetical order.
Syntax
AppendItem(&Elem)
Description
Use this method to append an element as the last element of the collection. The item must be instantiated first by using the CreateItem method.
Parameters
&Elem |
Specifies the element to be appended as an object: a Collection object, a Compound object, or a Primitive object. |
Returns
A Boolean value: True if the append was completed successfully, False otherwise.
Example
The following example demonstrates how to use Collection and Compound methods to create, populate, and append a compound item within a collection:
Local DocumentKey &DOCKEY; Local Document &DOC; Local Compound &COM, &Com_Rdr; Local Collection &Coll_Rdr; Local Primitive &PRIM; &DOCKEY = CreateDocumentKey("FlightStatus", "FlightData", "v1"); &DOC = CreateDocument(&DOCKEY); &COM = &DOC.DocumentElement; &Coll_Rdr = &COM.GetPropertyByName("RdrCollection"); &Com_Rdr = &Coll_Rdr.CreateItem(); &PRIM = &Com_Rdr.GetPropertyByName("QE_ACNUMBER"); &PRIM.Value = 105; &PRIM = &Com_Rdr.GetPropertyByName("QE_AZIMUTH"); &PRIM.Value = "40"; &PRIM = &Com_Rdr.GetPropertyByIndex(3); &PRIM.Value = "4B"; &nRet = &Coll_Rdr.AppendItem(&Com_Rdr);
See Also
CreateItem, CollectionElementType.
Syntax
CreateItem()
Description
Use this method to instantiate an empty object for this collection as defined by the CollectionElementType property.
Parameters
None.
Returns
A Collection object, a Compound object, or a Primitive object as defined by the CollectionElementType property.
See Also
AppendItem, InsertItem, CollectionElementType.
Syntax
DeleteItem(index)
Description
Use this method to delete the specified element from the collection.
Parameters
index |
Specifies the sequence number of the element to be deleted as an integer. |
Returns
A Boolean value: True if the delete was successful, False otherwise.
Syntax
GetItem(index)
Description
Use this method to return the specified element from the collection.
Parameters
index |
Specifies the sequence number of the element to be retrieved as an integer. |
Returns
A Collection object, a Compound object, or a Primitive object as defined by the CollectionElementType property.
See Also
Syntax
GetParent()
Description
Use this method to return the parent object of the collection element.
Parameters
None.
Returns
A Collection object or a Compound object.
See Also
Syntax
GetPath()
Description
Use this method to return the absolute path to the collection element within the document's structure.
For example, for the Item_Collection collection of the PuchaseOrder document, GetPath would return the following absolute path:
PurchaseOrder/Item_Collection
Parameters
None.
Returns
A string representing the absolute path to the collection element.
Syntax
InsertItem(&Elem, index)
Description
Use this method to insert an element at the specified location in the collection. The item must be instantiated first by using the CreateItem method.
Parameters
&Elem |
Specifies the element to be inserted as an object: a Collection object, a Compound object, or a Primitive object. |
index |
Specifies the sequence number for the element to be inserted as an integer. |
Returns
A Boolean value : True if the insertion was completed successfully, False otherwise.
Example
For example, for a collection with four items (a, b, c, d), the following call to insert item f would result in a collection with five items (a, f, b, c, d):
&ret = &Coll.InsertItem(&f, 2);
See Also
CreateItem, CollectionElementType.
In this section, the Collection class properties are presented in alphabetical order.
Description
Use this property to return the element type for the collection items as an integer constant. The values are:
Numeric Value |
Constant Value |
Description |
2 |
%Document_Collection |
A Collection object. |
1 |
%Document_Compound |
A compound object. |
0 |
%Document_Primitive |
A primitive object. |
This property is read-only.
Description
Use this property to return the count of items in the collection as an integer.
This property is read-only.
Description
Use this property to return an integer indicating the maximum number of items in the collection. The integer constant %Document_OccursUnbounded indicates that there is no maximum.
This property is read-only.
Description
Use this property to return an integer indicating the minimum number of items in the collection.
This property is read-only.
Description
Use this property to return the type of this document element as an integer constant: %Document_Collection.
This property is read-only.
Description
Use this property to return a Boolean value indicating whether this collection element has been changed.
This property is read-only.
Description
Use this property to return a Boolean value indicating whether this collection included initial data when the document was loaded from the XML source.
This property is read-only.
Description
Use this property return a Boolean value indicating whether this collection element is required.
This property is read-only.
Description
Use this property to return the name of this element as a string.
This property is read-only.
Description
Use this property to return the system-assigned sequence number for this element as an integer.
This property is read-only.