Formula - Length
The length function, one of the Math functions in the Formula plugin for Search Field Expressions, returns the character count of each value in the content.
Syntax
length(content [, unique])
Parameters
| Parameter | Required | Description |
|---|---|---|
content |
✅ Yes | The values to measure: body, context, or another Formula function such as xPath or jsonPath. |
unique |
❌ No | Unquoted true or false; default true for this function. false: a value that appears several times counts every time. true: identical values count once. Values are compared as text, so 100 and 100.00 are different values. A quoted 'true' is an error. |
Returns
- One character count per value in
content; several input values give several counts (see Example 4). - To get a single number from several counts, wrap
lengthin max, min, sum, or avg (see max).
Quoting, nesting, and how content is resolved are described in the Formula language rules.
Examples
Example 1: Measure a city name in an XML order
Input
Message Body:
<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0">
<Order>
<Id>1337</Id>
<Amount>666</Amount>
<City>New York</City>
<Partner>QWNtZQ==</Partner>
</Order>
</ns0:Orders>
Formula
length(xPath('Orders/Order/City', body))
Result
8
New York is eight characters long, including the space.

length measures the extracted text, not the XML element, so the tags don't count.
Example 2: Measure the message body
Input
Message Body:
Nodinite
Formula
length(body)
Result
8

Nodinite has eight characters, so length returns 8.
Example 3: Measure a message context value
Input
Message Context:
| Key | Value |
|---|---|
Correlation Id |
demo001 |
Header#Content-Type |
Application/XML |
Formula
length(context('Correlation Id'))
Result
7

Only the Correlation Id key is read; its value demo001 has seven characters. The screenshot writes the function names as Length and Context; names are case-insensitive.
Example 4: Measure each value extracted from JSON
Input
Message Body:
{a:[{b:'This'},{b:'is'},{b:'Formula Plugin'}]}
Formula
length(jsonPath('a[*].b', body), true)
Result
4
2
14

jsonPath extracts three values, and length returns one count for each: This (4), is (2), and Formula Plugin (14).