Skip to main content
Think of functions as a special type of formatter that produces an output value, but does not require an input like the standard formatters do. Functions can be used by themselves or as the start of a more complex expression, where other formatters are piped in after it. For example, [vault(foo)] can be resolved by itself, but you can also use it as the start of an expression (for example, [vault(foo) | equals(bar)] to check if the foo vault value is equal to bar).

CSV Functions

csv(value)

Used after loading data from a CSV file. The csvListRecords operation parses a CSV file, and the CSV formatter functions like other formatters by generating the values from a CSV document.
  • value: The string of CSV column headers to find the values from. If the CSV file does not have headers, columns can be accessed by a generic index (c1, c2, c3, …), if you set the requireheader attribute to false.

Example

In the following snippet, a CSV document is defined in memory in Script.
Next, the csvListRecords operation is called and CSV formatters are displayed from the sample CSV document.
Running this code displays the following output:

JSON Functions

hasjsonpath(jsonpath)

Checks if the input jsonpath exists in the JSON document and returns a boolean (true/false).
  • jsonpath: The relative jsonpath to check.

Example

isjsonpathnull(jsonpath, [ifTrue], [ifFalse])

Checks the input jsonpath and returns a boolean (true/false) if the jsonpath is null or does not exist.
  • jsonpath: The optional relative json to check.
  • ifTrue: The optional value to return if the formatter resolves to true.
  • ifFalse: The optional value to return if the formatter resolves to false.

Example

jsonpath(jsonpath)

You can use this formatter inside calls to JSON operations that have the JSON DOM available. You can use the jsonDOMSearch and jsonDOMGet operations to parse a JSON document. The jsonpath formatter is a formatter of the DOM object that functions like other formatters by generating the values from a JSON document. It returns the current jsonpath location of a JSON document. Optionally, you can supply a string of a relative jsonpath to find the associated JSON value.
  • jsonpath: The optional relative jsonpath to find the associated JSON value from.

Example

jsonsubtree(jsonpath)

You can use jsonsubtree to parse JSON subtrees from nested JSON structures.
  • jsonpath: The optional string of a relative jsonpath indicating which level of the structure to begin from.

Example

Three User entries under the /json/Event/Attendees object in the JSON data are included in the following script. The Attendees object is a subtree of the root object.
In this example, the jsonpath is the . character which instructs the script to use the current jsonpath based on where it is in the root object. Here, that path is /json/Event/Attendees, which returns all three entries. The following image shows how it appears in the Application log of the Logs page: jsonsubtree result in the Activity log Here is the raw JSON subtree result:
To show only the subtree for the second occurrence of the User jsonpath in /json/Event/Attendees, replace the path inside the jsonsubtree formatter call with jsonsubtree(User/\[2\]). This results in the following output:

jsontype(jsonpath)

Returns the data type (string, number, object, array, or boolean) of the current JSON name-value pair.
  • jsonpath: The optional relative jsonpath to find the associated JSON value from.

Example

XML Functions

hasxpath(xpath)

Checks to see if the input xpath exists in the XML document and returns a boolean (true/false).
  • xpath: The relative xpath to check.

Example

isxpathnull(xpath, [ifTrue], [ifFalse])

Checks the input xpath and returns a boolean in the form of the xsi:nil XML attribute (xsi:nil="true/false") if the xpath is null or does not exist. Use the ifTrue and ifFalse parameters to specify alternate values when the condition is and is not met.
  • xpath: The optional relative xpath to check.
  • ifTrue: The optional value to be returned if the formatter resolves to true.
  • ifFalse: The optional value to be returned if the formatter resolves to false.

Example

xpath(xpath)

Used inside calls to XML operations that have the XML DOM available. You can use the xmlDOMSearch and xmlDOMGet operations to parse an XML document. The XPath formatter is a formatter of the DOM object that functions like other formatters by generating values from an XML document. It returns the current XPath location of an XML document.
  • xpath: The optional string of a relative XPath to find the associated XML value from.

Example

In the following snippet, an XML document is defined in memory in Script.
In this snippet, the xmlDOMSearch operation is called and XPath formatters are displayed from the sample XML document.
When run against the preceding XML document, this code displays the following output.
The XPath formatter displays the three A elements that are iterated over, but only Value_Three from the final B element is displayed because [xpath(B)] ignores the values in other elements.

xpathcount(xpath)

Similar to the XPath formatter, except that it returns the count of the elements that match the provided XPath. Used inside calls to XML operations that have the XML DOM available. You can use the xmlDOMSearch and xmlDOMGet operations to parse an XML document. The XPathCount formatter is a formatter of the DOM object that functions like other formatters by generating counts from an XML document.
  • xpath: The optional string of a relative XPath from which to calculate the count.

Example

When this code is run, it returns 2 as output.

xsubtree(xpath)

Parse XML trees from nested XML structures.
  • xpath: The optional string of a relative XPath indicating which level of the structure to begin from.

Example

In the example XML document below, there are three entries under /Event/Attendees.
The . character in the xsubtree command instructs the script to use the current xpath. In this example, that path is /Event/Attendees, which returns all three entries:
To show only the subtree for the second occurrence of the User xpath in /Event/Attendees, replace the command with xsubtree(User[2]). The result of that is:

Other Functions

guid(includehyphens)

Generates a globally-unique identifier (GUID) value. By default, the formatter returns all of the characters in a single, unformatted string. To include hyphens that conform to the standard 8-4-4-4-12 GUID format, use the includehyphens parameter, and set it to true.
  • includehyphens: Set to true to include hyphens in the GUID being returned.
This formatter does not modify the input attribute (variable), so no such input attribute is required.

Example

vault(ItemName, [ifnotexists])

Returns the value of a vault item in the Global Settings Vault that matches the provided value for ItemName. By default, if the vault item does not exist, an error is thrown.
  • ItemName: The name of the vault item to retrieve.
  • ifnotexists: To prevent an error being thrown if a vault item does not exist, supply this optional parameter and a default value such as value does not exist. That value is returned when no vault item with the specified ItemName exists.
Use caution when referring to encrypted vault items in scripting contexts to ensure that sensitive information is not included in the logs.

Example