---
title: "Formula - context: Read Message Context Property Values"
description: The context Formula function returns the value of a Message Context property of a Log Event, by exact key or by a regular expression on the key. Includes syntax, parameters, and examples.
---

# <i class="fal fa-function" aria-hidden="true"></i> Formula - Context

The `context` [Formula][] function returns the value of one or more [Message Context properties][JSON Log Event - Context] (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)][hero]  
*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`.*  

## <i class="fal fa-code" aria-hidden="true"></i> Syntax

```text
context('Key')
context(regex('Key pattern'))
```

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

* `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][].

## <i class="fal fa-list-ol" aria-hidden="true"></i> Examples

### Example 1: Read the correlation ID

#### Input

|Key|Value|  
|---|---|  
|Correlation Id|demo001|  
|Header#Content-Type|Application/XML|  

#### Formula

```text
context('Correlation Id')
```

#### Result

```text
demo001
```

![Test Expression tab, Message Context: Context('Correlation Id') returns demo001 (7.12)][1]  
*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

#### Input

|Key|Value|  
|---|---|  
|Order#123|OK|  
|Order#456|OK|  
|Order#789|Fail|  

#### Formula

```text
context(regex('Order[#].*'))
```

#### Result

```text
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)][ex2]  
*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

#### Input

|Key|Value|  
|---|---|  
|OrderNumber|`<Id>3</Id>`|  

#### Formula

```text
xpath('Id', context('OrderNumber'))
```

#### Result

```text
3
```

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

## <i class="fal fa-circle-info" aria-hidden="true"></i> Notes

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

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Add or manage Search Field][]  
* <i class="fal fa-flask" aria-hidden="true"></i> [Test Your Expression][]  
* <i class="fal fa-hard-drive" aria-hidden="true"></i> [Add or manage Log View][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-envelope" aria-hidden="true"></i> [body][]  
* <i class="fal fa-tags" aria-hidden="true"></i> [contextKey][]  
* <i class="fal fa-table-list" aria-hidden="true"></i> [field][]  
* <i class="fal fa-function" aria-hidden="true"></i> [Formula][]  
* <i class="fal fa-scroll" aria-hidden="true"></i> [Formula language rules][]  
* <i class="fal fa-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-envelope" aria-hidden="true"></i> [Log Event][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [Message Context Key plugin][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [RegEx on Message Context plugin][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [XPath on Message Context plugin][]  
* <i class="fal fa-key" aria-hidden="true"></i> [Context Properties tab in a Log View][Context Properties tab]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Source/Context.png

[Add or manage Log View]:https://docs.nodinite.com/administration/log-management/log-views/features/add-or-manage-log-view/
[Add or manage Search Field]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Context Properties tab]:https://docs.nodinite.com/getting-started/log/see-the-details-of-a-log-event/#context-properties
[contextKey]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/contextkey/
[ex2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Source/context_Example2.png
[ex3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Source/context_Example3.png
[field]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/field/
[Formula]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/
[Formula language rules]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/overview/#fa-scroll-formula-language-rules
[hero]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Source/Formula_Context.gif
[JSON Log Event - Context]:https://docs.nodinite.com/core-services/log-event/features/json-log-event/#context
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Message Context Key plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/message-context-key/
[Order-to-Cash demo]:https://docs.nodinite.com/repository-model/bpms/examples/order-to-cash/generate-o2c-demo-data/
[regex]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regex/
[RegEx on Message Context plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/regex-on-message-context/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[xPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/
[XPath on Message Context plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath-on-message-context/