Transaction
Purpose¶
XML transaction manipulation and processing.
Note
TI stands for TransactionInfo and is the most commonly used business transaction manipulated by Platform 6. For backward compatibility a TransactionInfo transaction has a dataPartition (TRANSACTION) and a dataType (TransactionInfo).
Methods¶
Binding name: p6.transaction
buildPK¶
Build a transaction item primary key (TransactionPK) from it’s constituent parts.
Syntax
TransactionPK p6.transaction.buildPK(String dataType, String... itemIds)
The dataType is a free text string without constraint. If you create a transaction from a bundled script,
it is important to use as a prefix the application key (ie. myApp.TransactionInfo).
This way you will be able to use specific filters inside views and also for the transaction tag mechanism.
Example
// Build a PK for an invoice transaction within the O2C application
def pk = p6.transaction.buildPK('O2C.TransactionInfo', 'INV-2024-0042', 'ACME-CORP')
p6.log.debug 'Transaction PK: ' + pk
buildTIPK¶
Build a transaction item primary key (TransactionPK) for a TransactionInfo using supplied itemIds.
Syntax
TransactionPK p6.transaction.buildTIPK(String... itemIds)
Example
// Build a TI primary key for a purchase order
def pk = p6.transaction.buildTIPK('PO-2024-1587', 'SUPPLIER-042')
p6.log.debug 'TI PK: ' + pk
getUsingPipelineRequest¶
Get the XML transaction as a String using the primary key values in the current pipeline.
Syntax
String p6.transaction.getUsingPipelineRequest()
Tip
Pipeline keys used are:
platform6.request.dataTypeplatform6.request.ids
Example
// Retrieve the transaction referenced by the current pipeline request
def xml = p6.transaction.getUsingPipelineRequest()
if (xml) {
p6.log.debug 'Retrieved transaction XML, length: ' + xml.length()
}
getPKUsingPipelineRequest¶
Get the primary key of the transaction using the primary key values in the current pipeline.
Syntax
TransactionPK p6.transaction.getPKUsingPipelineRequest()
Example
// Get the PK from pipeline and use it to fetch the transaction
def pk = p6.transaction.getPKUsingPipelineRequest()
def xml = p6.transaction.get(pk)
p6.log.debug 'Transaction content: ' + xml
getPKsUsingPipelineRequest¶
Get a list of primary keys of transactions using the primary key values in the current pipeline.
Syntax
List<BaseItemPK> p6.transaction.getPKsUsingPipelineRequest()
Tip
Pipeline keys used are:
platform6.request.dataTypeplatform6.request.ids
Example
// Process all transactions referenced in the current pipeline request
def pks = p6.transaction.getPKsUsingPipelineRequest()
p6.log.debug 'Found ' + pks.size() + ' transactions to process'
pks.each { pk ->
def xml = p6.transaction.get(pk)
p6.log.debug 'Processing: ' + pk
}
get¶
Get the XML transaction as a String using the supplied item primary key.
Syntax
String p6.transaction.get(TransactionPK pk)
Example
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
def invoiceXml = p6.transaction.get(pk)
p6.log.debug 'Invoice XML length: ' + invoiceXml.length()
getItemLinks¶
Get the itemLinks of a transaction.
Syntax
List<ItemLink> p6.transaction.getItemLinks(TransactionPK pk, String viewId)
Definition: ItemLink
The ItemLink contains the following fields:
- ids: array of ids
- view: the view id
- type
Example
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
def links = p6.transaction.getItemLinks(pk, 'O2C.InvoiceView')
links.each { link ->
p6.log.debug "Linked item: view=${link.view}, ids=${link.ids}"
}
exists¶
Return the XML transaction as a String using the supplied item primary key or null if not found.
Syntax
String p6.transaction.exists(TransactionPK pk)
Example
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
def xml = p6.transaction.exists(pk)
if (xml != null) {
p6.log.debug 'Transaction found'
} else {
p6.log.debug 'Transaction does not exist'
}
remove¶
Remove the XML transaction and return it’s content as a String using the supplied item primary key or null if not found.
Syntax
String p6.transaction.remove(TransactionPK pk)
Example
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
def removedXml = p6.transaction.remove(pk)
if (removedXml != null) {
p6.log.info 'Removed transaction: INV-2024-0042'
}
put¶
Stores the supplied XML transaction using the supplied item primary key.
Syntax
TransactionPK p6.transaction.put(String xml, TransactionPK pk)
Example
def invoiceXml = """<Invoice>
<InvoiceNumber>INV-2024-0042</InvoiceNumber>
<Supplier>ACME-CORP</Supplier>
<Amount currency="EUR">1250.00</Amount>
<Date>2024-03-15</Date>
</Invoice>"""
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
p6.transaction.put(invoiceXml, pk)
putTI¶
Stores the supplied XML as a TransactionInfo using supplied itemIds.
Syntax
TransactionPK p6.transaction.putTI(String xml, String... itemIds)
Example
def orderXml = """<PurchaseOrder>
<OrderNumber>PO-2024-1587</OrderNumber>
<Buyer>GlobalTrade Inc.</Buyer>
<TotalAmount currency="USD">5430.00</TotalAmount>
</PurchaseOrder>"""
p6.transaction.putTI(orderXml, 'PO-2024-1587', 'GLOBALTRADE')
saveTI¶
Projects the supplied XML (validates against a data model and stores) as a TransactionInfo using supplied itemIds.
Syntax
TransactionPK p6.transaction.saveTI(String xml, String... itemIds)
Example
def invoiceXml = """<Invoice>
<InvoiceNumber>INV-2024-0098</InvoiceNumber>
<Supplier>ACME-CORP</Supplier>
<Amount currency="EUR">3200.00</Amount>
</Invoice>"""
p6.transaction.saveTI(invoiceXml, 'INV-2024-0098', 'ACME-CORP')
save¶
Projects the supplied XML (using the supplied data model for content validation) using the supplied item primary key.
Syntax
TransactionPK p6.transaction.save(String xml, String dataModelName, TransactionPK pk)
Example
def invoiceXml = """<Invoice>
<InvoiceNumber>INV-2024-0098</InvoiceNumber>
<Supplier>ACME-CORP</Supplier>
<Amount currency="EUR">3200.00</Amount>
</Invoice>"""
def pk = p6.transaction.buildPK('O2C.TransactionInfo', 'INV-2024-0098', 'ACME-CORP')
p6.transaction.save(invoiceXml, 'TransactionInfo', pk)
saveAndRouteTI¶
Projects the supplied XML as a TransactionInfo using supplied itemIds and sends as a camel Exchange to the given Platform 6 routing endpoint.
Syntax
TransactionPK p6.transaction.saveAndRouteTI(String xml, String endpointUrl, String... itemIds)
Example
def invoiceXml = """<Invoice>
<InvoiceNumber>INV-2024-0098</InvoiceNumber>
<Supplier>ACME-CORP</Supplier>
<Amount currency="EUR">3200.00</Amount>
</Invoice>"""
// Save and route to the invoice processing pipeline
p6.transaction.saveAndRouteTI(invoiceXml, 'direct:p6router.1', 'INV-2024-0098', 'ACME-CORP')
saveAndRoute¶
Projects the supplied XML (using the supplied data model for content validation) using the supplied item primary key and sends as a camel Exchange to the given Platform 6 routing endpoint.
Syntax
TransactionPK p6.transaction.saveAndRoute(
String xml,
String dataModelName,
TransactionPK pk,
String endpointUrl
)
Example
def invoiceXml = """<Invoice>
<InvoiceNumber>INV-2024-0098</InvoiceNumber>
<Supplier>ACME-CORP</Supplier>
<Amount currency="EUR">3200.00</Amount>
</Invoice>"""
def pk = p6.transaction.buildPK('O2C.TransactionInfo', 'INV-2024-0098', 'ACME-CORP')
p6.transaction.saveAndRoute(invoiceXml, 'TransactionInfo', pk, 'direct:p6router.1')
route¶
Sends the supplied item primary key as a camel Exchange to the given Platform 6 routing endpoint.
Syntax
TransactionPK p6.transaction.route(TransactionPK pk, String endpointUrl)
Example
// Route an existing transaction to a different processing endpoint
def pk = p6.transaction.buildTIPK('INV-2024-0098', 'ACME-CORP')
p6.transaction.route(pk, 'direct:p6router.1')
validate¶
Validate the supplied XML against the schema found at the supplied URI.
Syntax
boolean p6.transaction.validate(String xml, String schemaUri)
Tip
Any errors are added to the pipeline as entry errors encoded as a String.
Example
def invoiceXml = p6.pipeline.get('invoiceXml')
def isValid = p6.transaction.validate(invoiceXml, 'p6file://${P6_DATA}/resources/schemas/pidx_v1_0/schema.xsd')
if (!isValid) {
def errors = p6.pipeline.get('errors')
p6.log.error 'Validation failed: ' + errors
}
validate (with provider)¶
Deprecated
Since 6.10.7, this method is marked as deprecated.
Validate the supplied XML using the given validation provider and provider parameters
Syntax
boolean p6.transaction.validate(
TransactionValidationProvider provider,
String xml,
String... providerParams
)
TransactionValidationProvider definition
Validation providers supported by Platform 6 in this release:
p6.transactionProvider.PHIVE - Since 6.10.7
Requires the Phax sidecar be installed on the instance, speak to R&D/dev-ops
- param[0]: VESID (mandatory)
Tip
Any errors are added to the pipeline as entry errors encoded as a String.
Example
def invoiceXml = p6.pipeline.get('invoiceXml')
def isValid = p6.transaction.validate(p6.transactionprovider.PHIVE, invoiceXml, 'org.oasis-open:invoice:2.1')
if (!isValid) {
p6.log.error 'UBL Invoice validation failed: ' + p6.pipeline.get('errors')
}
validate (with provider)¶
New Feature
Since 6.10.7
Validate XML, located at the supplied URI, using the given validation provider and vesId
Warning
Requires phase4 sidecar to be deployed, contact R&D/devops.
Syntax
WithMethod<Boolean> p6.transaction.validate(String fileToValidate)
Tip
Any errors are added to the pipeline, as a String of comma-seperated reasons, as validate.failure.reasons.
Example
def isValid = p6.transaction.validate 'p6file://${P6_DATA}/resources/documents/invoice/invoice.xml' with 'org.oasis-open:invoice:2.1'
if (!isValid) {
p6.log.info 'Invalid document due to: ' + p6.pipeline.get('validate.failure.reasons')
}
updateFlags¶
Update the flags inside a transaction. Set a flag to true to add the flag and false to remove the flag.
Syntax
String p6.transaction.updateFlags(TransactionPK pk, String viewId, Map<String, Boolean> flags)
The transaction’s flags are returned by the method.
Example
Unmark as unread
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
p6.transaction.updateFlags(pk, 'O2C.InvoiceView', ['eunread': false])
Mark as visible and unread
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
def flags = p6.transaction.updateFlags(pk, 'O2C.InvoiceView', ['eunread': true, 'aavisible': true])
p6.log.debug 'Updated flags: ' + flags
getAsXML¶
Returns the parsed XML of the transaction.
Syntax
GPathResult p6.transaction.getAsXML(TransactionPK pk)
Example
def pk = p6.transaction.buildTIPK('INV-2024-0042', 'ACME-CORP')
def xml = p6.transaction.getAsXML(pk)
p6.log.debug 'Invoice number: ' + xml.InvoiceNumber.text()
p6.log.debug 'Amount: ' + xml.Amount.text() + ' ' + xml.Amount.@currency.text()
getTIAsXML¶
Returns the parsed XML of the TransactionInfo transaction based on the itemIds.
Syntax
GPathResult p6.transaction.getTIAsXML(String... itemsIds)
Example
def xml = p6.transaction.getTIAsXML('INV-2024-0042', 'ACME-CORP')
p6.log.debug 'Supplier: ' + xml.Supplier.text()