Skip to content

$Xml

Provides access to the process data model. $Xml is an instance of the XmlNode object and points to the root of the workflow instance pool.

1
const $Xml: Xml;

Remarks

Reference Point

The $Xml object points to different elements depending on where it is used:

  • In Pre-Work, Post-Work, Role, and Route scripts, $Xml is bound to the process pool element.
  • In Rule-Based Validation and Formatting rules, $Xml is bound to the control element.

Relative XPath expressions start at that element. See Script Contexts for the XML scope of each script type.

Pool Element

The pool element is created at the root of the XML tree by default. However, sub-workflow instances may use any element in the data tree. In the product process, $Xml points to the Product element. For the Order process (as a sub-workflow of the Product process), $Xml points to the Order element where the sub-workflow is initiated. For rules on the Amount field, $Xml points to the Amount element.

Accessing Pool Root

Because $Xml may point to different elements in the data model, in some cases you may need to access the pool root element. Use the $poolRoot variable, or an absolute XPath that starts at the document element, such as /*[1]/Product. Do not write paths such as Product/Id from a nested element: relative paths always start at the current element.

Examples

Read and update process data

1
2
3
4
5
6
7
var customerName = $Xml.Evaluate('Customer/Name');

$Xml.SelectAll('Lines/Line', function (line) {
    line.SetDefaultValue('Quantity', 1);
});

$Xml.SetValue('Approved', true);

Example Data Model for Pool

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<form>
  <Product>
    <Id>1234</Id>
    <Orders>
      <Order>
        <Id>4567</Id>
        <Amount>1</Amount>
      </Order>
      <Order>
        <Id>8901</Id>
        <Amount>2</Amount>
      </Order>
    </Orders>
  </Product>
</form>

Read values relative to the pool element of the Product process

1
2
var productId = $Xml.Evaluate('Id');                        // '1234'
var totalAmount = $Xml.Sum('Orders/Order/Amount');          // 3

Read values in a sub-workflow started for an Order element

1
2
var orderId = $Xml.Evaluate('Id');                          // '4567' or '8901'
var productId = $Xml.Evaluate('../../Id');                  // '1234'

Accessing the pool root with the

$poolRoot variable:

1
var productId = $Xml.Evaluate('$poolRoot/Id');

Using an absolute XPath to access the pool root

1
var productId = $Xml.Evaluate('/*[1]/Product/Id');

Capabilities

Namespaces

Structure Changes

  • $Xml.AppendChild: Appends a new child to the specified XPath location and executes the provided callback function on the newly created node before inserting it into the DOM. Returns the appended new node.
  • $Xml.Clone: Creates a detached deep copy of the current node.
  • $Xml.Copy: Copies the current XML node and all its child nodes from the source XPath to the target XPath or target navigator.
  • $Xml.Remove: Removes the current node and returns it in an array.
  • $Xml.Sync: Synchronizes the nodes at the specified XPath with the input nodes, and returns an array of the synchronized nodes.

Validation and Cleanup

  • $Xml.Assert: Performs an error check by asserting that the specified XPath evaluates to a boolean true value. If the assertion fails, an error is thrown.
  • $Xml.CommitDeletes: Deletes all child nodes that have the State attribute set to the value 'Deleted'.

Client Events

  • $Xml.Bind: Attaches a change event handler to the nodes selected by the specified XPath.
  • $Xml.Live: Attaches a change event handler to the specified XPath.
  • $Xml.Trigger: Triggers event handlers bound to the current node.

Reading and Predicates

  • $Xml.Count: Returns the number of nodes at the specified XPath.
  • $Xml.Equals: Returns a boolean value indicating whether the current node has the specified value.
  • $Xml.Evaluate: Returns the string value of the current node.
  • $Xml.EvaluateBoolean: Returns the boolean value of the current node.
  • $Xml.EvaluateDateTime: Returns the date-time offset value of the current node.
  • $Xml.EvaluateNumber: Returns the numeric value of the current node.
  • $Xml.IsEmpty: Returns a boolean value indicating whether the current node has an empty string value.
  • $Xml.Sum: Returns the sum of the numeric values of child elements on the current node, or at the specified XPath.

Creation and Persistence

Formatting and Transformation

  • $Xml.Format: Applies the specified template to the current node and returns the resulting string.
  • $Xml.FormatAll: Applies the specified template to every node selected by the XPath and joins the results with a separator.
  • $Xml.InnerXml: Returns the inner XML of the current node.
  • $Xml.OuterXml: Returns the outer XML of the current node.
  • $Xml.Transform: Performs an XSLT transformation on the current node and returns the result as a string.

Attributes

Selection and Navigation

  • $Xml.GetParent: Returns the parent node of the current node.
  • $Xml.HasNode: Returns a boolean value indicating whether the specified XPath selects at least one node.
  • $Xml.LocalName: Returns the local name of the current node, without its namespace prefix.
  • $Xml.SelectAll: Selects all matching nodes based on the specified XPath expression.
  • $Xml.SelectSingle: Selects a single node based on the specified XPath expression.

Value Updates