Skip to content
Documentation
Updated 3 minutes to read
Markdown

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.

Measure the customer name in the body and the order number in the message context of an Order-to-Cash event with length, animated walkthrough (7.12)
Animated walkthrough: on the JSON Order Received event of order ORD-10005 in the Order-to-Cash demo, length(jsonPath('$.customer.name', body)) returns 13 for Tailspin Toys, the space included. On the Message Context tab, length(context('OrderNumber')) returns 9 for ORD-10005.

length(content [, unique])
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.
  • 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 length in max, min, sum, or avg (see max).

Quoting, nesting, and how content is resolved are described in the Formula language rules.

Example 1: Measure a city name in an XML order

Section titled “Example 1: Measure a city name in an XML order”

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>
length(xPath('Orders/Order/City', body))
8

New York is eight characters long, including the space.

Test Expression tab: length(xPath('Orders/Order/City', body)) on an order with City New York returns 8 (7.12)
length measures the extracted text, not the XML element, so the tags don't count.

Message Body:

Nodinite
length(body)
8

Test Expression tab: length(body) on the message body Nodinite returns 8 (7.12)
Nodinite has eight characters, so length returns 8.

Example 3: Measure a message context value

Section titled “Example 3: Measure a message context value”

Message Context:

Key Value
Correlation Id demo001
Header#Content-Type Application/XML
length(context('Correlation Id'))
7

Test Expression tab: length(context('Correlation Id')) on the context value demo001 returns 7 (7.12)
Only the Correlation Id key is read; its value demo001 has seven characters.

Example 4: Measure each value extracted from JSON

Section titled “Example 4: Measure each value extracted from JSON”

Message Body:

{a:[{b:'This'},{b:'is'},{b:'Formula Plugin'}]}
length(jsonPath('a[*].b', body), true)
4
2
14

Test Expression tab: length of the jsonPath values of every b in the array a, with unique true, returns 4, 2, and 14 (7.12)
jsonPath extracts three values, and length returns one count for each: This (4), is (2), and Formula Plugin (14).

...

Version:
Release date: N/A
Loading...

Explore Nodinite for 30 days – completely free

  • Find out why this is the leading O&M software
  • Prove your business case
  • Test the self-service for the business side

Loading...

See how Nodinite resolves your technical issues, in a LIVE Demo!

Once you submit this request:

  • We will give you a short call to understand the issues you want to tackle.
  • Understand solutions you have tried and why were you not happy with them.
  • Book a convenient slot for a LIVE demo!

Loading...