Skip to content

Table

Purpose

Data table lookup.

Methods

Binding name: p6.table


Method: Map[String,List] get(String tableId [, String appKey])

Returns the fields and keys of the table.


Method: List<String> listAll()

Returns all the table names.

Note

If the item is related to an application, the name will be appkey.name.


Method: List<String> list([String appKey])

Returns all table names of an application. If no appKey is given or empty, only unbundled tables are listed.


Method: String[] lookup(String tableId, Map keys, String fieldName)

Performs a lookup on the given data table tableId using the Map of conditions (list of key=value). Only fieldName values will be returned.


Method: Map[] lookup(String tableId, Map keys)

Performs a lookup on the given data table tableId using the Map of conditions (list of key=value). The table records found are returned as an array of Maps of fieldName and values.


Method: void upsert(String tableId, List<Map<String, String>> records)

Upsert the records in the table named tabledId. If a new record has the same values for the primary keys than an existing record, the existing record’s values are updated with the new ones. If not, the new record is added to the table. If the list of records is empty, nothing happens.


Method: void insert(String tableId, List<Map<String, String>> records)

Insert the records in the table named tabledId. If a new record has the same values for the primary keys as an existing record then an exception is raised. If not, the new record is added to the table. If the list of records is empty, nothing happens.


Method: String updateIndexes(String tableId)

Start the indexation job for the table. A P6Exception is thrown if the job is already running for this table.


Method: void delete(String tableId, List<Map<String, String>> records)

Delete the records from the table named tabledId. If the list of records is empty, nothing happens.


Method: Map[] toList(String tableId)

Performs a lookup on the given data table tableId returning all rows and values.


Method: GPathResult toXml(String tableId, String xmlTemplateText)

Performs a lookup on the given data table tableId returning all rows and values expressed as XML. xmlTemplateText is optional. Use this to override the internal XML template used.


Method: org.w3c.dom.Document toDom(String tableId, String xmlTemplateText)

Performs a lookup on the given data table tableId returning all rows and values expressed as a DOM. xmlTemplateText is optional. Use this to override the internal XML template used.

Default table XML structure:

<table>
    <TABLENAME>
        <rows>
            <row id="0">
                <key id="FIELDNAME1">fvalue1</key>
                <key id="FIELDNAME2">fvalue2</key>
            </row>
        </rows>
    </TABLENAME>
</table>

Examples

Accessing data table records:

def records = p6.table.lookup("Customers", [Cust_ERP_Identifier: "MHP"])
println records
Accessing a single field by name from a data table:
if(p6.table.lookup("Customers", [Cust_ERP_Identifier: "MHP"], "Invoice_Aggregation") == ["true"]){
   println "Invoice aggregation is required!"
}

Reindexing a table

println "Indexing job: " + p6.table.updateIndexes("Customers")

p6.table.listAll().each { println it }
p6.table.list().each { println it }
p6.table.list("p6_demo").each { println it }
def item = p6.table.get("Customers")
println "Fields:"
item['fields'].each { println it }

println "Keys:"
item['keys'].each { println it }