Formula - Context
Section titled “ Formula - Context”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.

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.
Syntax
Section titled “ Syntax”context('Key')context(regex('Key pattern'))Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”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.
Examples
Section titled “ Examples”Example 1: Read the correlation ID
Section titled “Example 1: Read the correlation ID”| Key | Value |
|---|---|
| Correlation Id | demo001 |
| Header#Content-Type | Application/XML |
Formula
Section titled “Formula”context('Correlation Id')Result
Section titled “Result”demo001
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 |
Formula
Section titled “Formula”context(regex('Order[#].*'))Result
Section titled “Result”OKFailAll 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 onlyOrder#and finds nothing.
See the Formula language rules for the details.

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> |
Formula
Section titled “Formula”xpath('Id', context('OrderNumber'))Result
Section titled “Result”3
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 asHeader#. contextreads the Message Context only; it never reads the message body. Use body for the payload.