Skip to content
Documentation
Updated 3 minutes to read
Markdown

The context Formula function returns the value of one or more Message Context properties (key/value pairs) of the Log Event, such as a correlation ID or an HTTP header.

Read an order number and then every customer key from the Message Context of an Order-to-Cash event with context, animated walkthrough (7.12)
Animated walkthrough: on the logged Message Context of the Order Received event of order ORD-10005 in the Order-to-Cash demo, context('OrderNumber') returns ORD-10005, and context(regex('Customer.*')) returns the values of both CustomerId and CustomerName: CUST-005 and Tailspin Toys.

context('Key')
context(regex('Key pattern'))
Parameter Required Description
'Key' Yes (first form) The exact name of the context property, in single quotes.
regex('Key pattern') Yes (second form) A regex on the key names. Every context property whose key matches contributes its value.
  • context('Key') returns the value of that context property, or nothing when the Log Event has no such key.
  • context(regex('Key pattern')) returns the values of all matching context properties; duplicates are collapsed (see Formula language rules).

To get the key names instead of the values, use contextKey.

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

Test Expression tab, Message Context: Context('Correlation Id') returns demo001 (7.12)
The Correlation Id key matches exactly, so only its value demo001 is returned. The screenshot writes Context; function names are case-insensitive.

Example 2: Read the status of every order key

Section titled “Example 2: Read the status of every order key”
Key Value
Order#123 OK
Order#456 OK
Order#789 Fail
context(regex('Order[#].*'))
OK
Fail

All three keys match the pattern; the duplicate OK is collapsed into one unique value, so the test shows 2 unique matches.

  • Write a literal # as [#] or \#. Formula regexes ignore unescaped whitespace and treat # as the start of a comment, so 'Order#.*' silently runs as 'Order' and returns nothing.
  • Match the whole key. context(regex(...)) reads the keys whose matched text equals a key name, so end the pattern with .*; '^Order[#]' matches only Order# and finds nothing.

See the Formula language rules for the details.

Test Expression tab: context with a regex on keys starting with Order and an escaped hash returns the unique values OK and Fail from three Order keys (7.12)
Three keys match Order[#].*, but the two OK values collapse into one, so the test reports 2 unique matches.

Example 3: Read XML stored in a context value

Section titled “Example 3: Read XML stored in a context value”
Key Value
OrderNumber <Id>3</Id>
xpath('Id', context('OrderNumber'))
3

Test Expression tab: xpath('Id', context('OrderNumber')) returns 3 from the XML stored in the OrderNumber key (7.12)
context returns the XML text stored in OrderNumber, and xpath reads the Id element from it; the same pattern works with jsonPath for JSON values.

  • The context key in context('Key') must match the stored key name exactly, including spaces and prefixes such as Header#.
  • context reads the Message Context only; it never reads the message body. Use body for the payload.

...

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...