---
title: "Formula Search Field Expression Plugin: Language Rules and Function Reference"
description: The Formula Search Field Expression plugin combines functions to extract, transform, and test values from the body, context, and fields of a Log Event. Learn the formula language rules, nesting, and every function.
---

# <i class="fal fa-function" aria-hidden="true"></i> Formula Search Field Expression Plugin

The **Formula** plugin extracts values from a [Log Event][] by combining functions, much like a formula in Microsoft Excel. Use it when a single plugin isn't enough: to extract and then transform a value, to combine values from the body and the context, to count or sum, or to look up a value in a SQL database.

* ✅ Extract from the message body, context properties, and Log Event fields in one expression  
* ✅ Nest functions: the result of one function is the content of the next  
* ✅ Convert, alter, test, and calculate on the extracted values  

![Build a nested Formula on an Order Received event and test it, animated walkthrough (7.12)][3]  
*Animated walkthrough: on the Order Received JSON of the [Order-to-Cash demo][], `concat(jsonPath('$.orderId', body), ' / ', toUpperCase(jsonPath('$.customer.name', body)))` nests three functions and returns one value, `ORD-10005 / TAILSPIN TOYS`.*  

<aside aria-label="Tip" class="nodinite-note nodinite-note--tip">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-lightbulb"></i> Tip</p>
<div class="nodinite-note__content"><p>Start with a dedicated plugin such as <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath/">XPath</a> or <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/json-path/">JSON Path</a> when it can do the job; see <a href="https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin">Choose a plugin</a>. Use Formula when you need to combine or transform.</p></div>
</aside>

---

## <i class="fal fa-brain-circuit" aria-hidden="true"></i> How a Formula Is Evaluated

A formula is evaluated from the inside out. A **source** function reads data from the [Log Event][]; every other function takes **content** (the output of the function inside it) and returns new content. The final result becomes the values of the [Search Field][Search Fields]. You check the result in the **Test Expression** tab; see [Test Your Expression][].

```mermaid
graph LR
    A["Log Event"] --> B["Source<br/>body, context, field"]
    B --> C["Extract<br/>xPath, jsonPath, regex, csv"]
    C --> D["Convert, Alter,<br/>Logical, Math"]
    D --> E["Search Field values"]
    style A fill:#2678BD,color:#fff
    style B fill:#3F827B,color:#fff
    style C fill:#E47528,color:#fff
    style D fill:#9E59BB,color:#fff
    style E fill:#93d16d,color:#000
```

*Diagram: a formula reads a source from the Log Event (blue), extracts values (orange), optionally transforms or tests them (purple), and returns the Search Field values (green) that users search for in [Log Views][]. Each color is one function group from the [Function reference](#fa-book-function-reference).*

### Nesting, Step by Step

#### Input

```xml
<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0">
  <Order>
    <Id>1337</Id>
    <Amount>666</Amount>
    <City>New York</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
  <Order>
    <Id>1338</Id>
    <Amount>42</Amount>
    <City>Paris</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
</ns0:Orders>
```

#### Formula

```text
count(xPath('Orders/Order/Id', body))
```

#### Evaluation

1. [body][] returns the whole message body.
2. `xPath('Orders/Order/Id', body)` ([xPath][]) returns two values: `1337` and `1338`. The path needs no namespace prefix.
3. `count(...)` ([count][]) counts them.

#### Result

```text
2
```

![Test Expression tab: count(xPath('Orders/Order/Id', body)) on a message with two orders returns 2 (7.12)][2]  
*The nested formula returns one value, `2`: one count per matching `Id` element, which is why the test bench reports one unique match.*  

---

## <i class="fal fa-scroll" aria-hidden="true"></i> Formula language rules

These rules apply to every function. Function pages link here instead of repeating them.

|Rule|Details|Example|  
|---|---|---|  
|**Content**|The data a function works on: a source function (`body`, `context`, `field`) or the result of another function.|`toUpperCase(context('Region'))`|  
|**`body` has no parentheses**|Write `body`, not `body()`.|`regex('\d+', body)`|  
|**Strings use single quotes**|Every text argument is enclosed in `'…'`. Numbers are written as is.|`substring(0, 3, body)`|  
|**Escape a single quote by doubling it**|A literal `'` inside a string is written `''`.|`jsonPath('ord''erid', body)`|  
|**Backslashes are written once**|Regular expressions use normal .NET syntax; don't double backslashes.|`regex('\d+', body)`|  
|**`#` and spaces in regular expressions**|Formula regular expressions ignore unescaped whitespace and treat `#` as the start of a comment, and matching ignores case. Write a literal `#` as `[#]` or `\#` and a literal space as `\s` or `[ ]`. `'Order#.*'` silently runs as `'Order'`.|`context(regex('Order[#].*'))`|  
|**`context(regex(...))` must match the whole key**|The text the pattern matches is used as the key to read, so a partial match such as `'^Order[#]'` finds nothing. End the pattern with `.*`.|`context(regex('Order[#].*'))`|  
|**Field names are case-sensitive**|The name in `field('…')` must match the [Log Event][] field exactly; only function names ignore case.|`field('MessageGUID')`|  
|**Function names are case-insensitive**|`xpath`, `xPath`, and `XPATH` all work. The reference tables write them in camelCase; examples show them exactly as typed in their screenshot.|`jsonpath('a[*].b', body)`|  
|**Several values flow through**|Extract functions can return several values. The next function handles each value, and Math functions aggregate them.|`count(jsonPath('a[*].b', body))`|  
|**Search Field values are unique**|The values stored on a [Search Field][Search Fields] are unique; duplicates are collapsed. The [test bench][Test Your Expression] shows the **Number of unique matches**. Inside a formula, Math functions still see how often each value occurred; see `unique` below.|`3 6 6` → `3`, `6`|  
|**Logical functions return `true` or no value**|`equal`, `notEqual`, `startsWith`, and `endsWith` return `true` when the condition holds, and no value when it doesn't. When one argument returns several values, one match is enough; add an unquoted `true` as the last argument to require every value to match.|`startsWith('U', regex('GMT\|UTC', body))` → `true`|  
|**XPath ignores namespaces**|In [xPath][], element names match without namespace prefixes or declarations.|`xPath('Orders/Order/Id', body)` on `<ns0:Orders …>`|  

### Escaping Single Quotes

#### Input

```json
{"ord'erid":"123","name":"John Doe"}
```

#### Formula

```text
jsonpath('ord''erid',body)
```

#### Result

```text
123
```

![Escaped single quote in a jsonPath formula (7.12)][1]  
*The key `ord'erid` is written `ord''erid` inside the quoted JSONPath expression of [jsonPath][].*  

---

## <i class="fal fa-book" aria-hidden="true"></i> Function reference

Each function has its own page with parameters, return values, and examples.

### Source

Read data from the [Log Event][].

|Function|Returns|  
|---|---|  
|[body][]|The whole message body as text|  
|[context('Key')][context]|The value of one context property|  
|[context(regex('Key pattern'))][context]|The values of all context properties whose whole key matches the regular expression|  
|[contextKey(regex('Key pattern'))][contextKey]|The keys (not the values) of the context properties that match|  
|[field('fieldName')][field]|The value of a Log Event field (case-sensitive name)|  

### Extract

Pick values out of structured or unstructured content.

|Function|Returns|  
|---|---|  
|[csv(headerRowsToSkip, 'delimiter', columnIndex, 'commentSymbol', content)][csv]|The values of one column (zero-based) of delimited text|  
|[jsonPath('expression', content)][jsonPath]|The values that match a JSONPath expression|  
|[jsonPathKey('expression', content)][jsonPathKey]|The property names (keys) that match a JSONPath expression|  
|[regex('expression', content)][regex]|The whole matches of a regular expression|  
|[regexGroup('expression', 'groups', content)][regexGroup]|The captured groups of a regular expression|  
|[sqllookup('connectionStringId', 'database', 'table', 'searchColumn', 'resultColumn', content)][sqllookup]|A value looked up in a SQL Server table|  
|[xPath('expression', content)][xPath]|The values that match an XPath 1.0 expression|  
|[xPath2('expression', content)][xPath2]|The values that match a full XPath expression over the whole document|  

### Convert

Change the encoding or case of content.

|Function|Returns|  
|---|---|  
|[base64decode(content [, 'source encoding'])][base64decode]|Decoded text from base64|  
|[base64encode(content [, 'input encoding'])][base64encode]|Base64 text|  
|[convert('source encoding', 'target encoding', content)][convert]|Content re-encoded from one character encoding to another|  
|[toLowerCase(content)][toLowerCase]|Lowercase text|  
|[toUpperCase(content)][toUpperCase]|Uppercase text|  

### Alter

Change text.

|Function|Returns|  
|---|---|  
|[concat(content, ..., content)][concat]|All arguments joined into one string|  
|[removebom(content)][removebom]|Content without a leading byte order mark (BOM)|  
|[replace('oldValue', 'newValue', content)][replace]|Content with every occurrence of a text replaced|  
|[replaceregex('pattern', 'newValue', content)][replaceregex]|Content with every regular expression match replaced|  
|[substring(startIndex, length, content)][substring]|Part of the text, from a zero-based start index|  

### Logical

Test content.

|Function|Returns|  
|---|---|  
|[equal('expression', content [, matchAllValues])][equal]|`true` when content equals the expression|  
|[notEqual('expression', content [, matchAllValues])][notEqual]|`true` when content differs from the expression|  
|[isnull(content, 'default')][isnull]|The default when content is null or empty, else the content|  
|[startsWith('expression', content [, matchAllValues])][startsWith]|`true` when content starts with the expression|  
|[endsWith('expression', content [, matchAllValues])][endsWith]|`true` when content ends with the expression|  

### Math

Aggregate and round values. The optional `unique` argument of the aggregating functions is an unquoted `true` or `false`: with `false`, a value that occurs several times counts every time (two invoice lines of `100` → `sum` = `200`); with `true`, identical values count once (→ `100`). Values are compared as text, so `100` and `100.00` are different. The default differs per function, as shown below; leave it `false` for totals. [round][] doesn't aggregate and has no `unique` argument.

|Function|Returns|  
|---|---|  
|[avg(content [, unique])][avg]|The average of the numeric values; `unique` defaults to `false`|  
|[count(content [, unique])][count]|The number of values; `unique` defaults to `true`|  
|[length(content [, unique])][length]|The length in characters of the content; `unique` defaults to `true`|  
|[max(content [, unique])][max]|The largest numeric value; `unique` defaults to `true`|  
|[min(content [, unique])][min]|The smallest numeric value; `unique` defaults to `true`|  
|[round(content, decimals)][round]|Every numeric value rounded to the given decimals, midpoints away from zero (<sup><span class="nodinite-new-badge">New 7.12</span></sup>)|  
|[sum(content [, unique])][sum]|The sum of the numeric values; `unique` defaults to `false`|  

---

## <i class="fal fa-triangle-exclamation" aria-hidden="true"></i> Performance

* Every formula runs for every matching [Log Event][] during logging and [re-index][How a Re-Index Runs]; keep formulas as short as the job allows.
* Use [xPath][] (XPath 1.0, forward-only reader, see [Allowed XPath expressions][]) for large XML; use [xPath2][] only when you need look-back steps or predicates on child elements.
* `sqllookup` queries SQL Server for each evaluation; see [sqllookup][] before using it on high-volume [Message Types][].

## <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-puzzle-piece" aria-hidden="true"></i> [Search Field Expressions][]  
* <i class="fal fa-signs-post" aria-hidden="true"></i> [Choose a plugin][]  
* <i class="fal fa-magnifying-glass-plus" aria-hidden="true"></i> [Search Fields][]  
* <i class="fal fa-file" aria-hidden="true"></i> [Message Types][]  
* <i class="fal fa-envelope" aria-hidden="true"></i> [Log Event][]  
* <i class="fal fa-language" aria-hidden="true"></i> [Character Encoding][]  
* <i class="fal fa-wand-magic-sparkles" aria-hidden="true"></i> [Search Field Wizard][]  
* <i class="fal fa-list-check" aria-hidden="true"></i> [Allowed XPath expressions][]  
* <i class="fal fa-search" aria-hidden="true"></i> [Log Views][]  
* <i class="fal fa-magnifying-glass" aria-hidden="true"></i> [Search with Log Views (end-user guide)][Log Overview]  

[1]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/SingleQuotes.png
[2]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Math/count_Example1.png
[3]:https://docs.nodinite.com/media/Documentation%20Pictures/IM/WebClient/Admin/Log/Search%20Fields/Plugins/Formula/Formula_Nesting.gif

[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/
[Allowed XPath expressions]:https://docs.nodinite.com/administration/log-management/search-fields/troubleshooting/allowed-xpath-expressions/
[avg]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/average/
[base64decode]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/base64decode/
[base64encode]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/base64encode/
[body]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/body/
[Character Encoding]:https://docs.nodinite.com/core-services/log-event/features/character-encoding/
[Choose a plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/#fa-signs-post-choose-a-plugin
[concat]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/concat/
[Context]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/context/
[contextKey]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/contextkey/
[convert]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/convert/
[count]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/count/
[csv]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/csv/
[endsWith]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/logical/endswith/
[equal]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/logical/equal/
[field]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/source/field/
[How a Re-Index Runs]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#how-a-re-index-runs
[isnull]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/logical/isnull/
[JSON Path plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/json-path/
[jsonPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpath/
[jsonPathKey]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/jsonpathkey/
[length]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/length/
[Log Event]:https://docs.nodinite.com/core-services/log-event/overview/
[Log Overview]:https://docs.nodinite.com/getting-started/log/overview/
[Log Views]:https://docs.nodinite.com/administration/log-management/log-views/features/what-is-a-log-view/
[max]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/max/
[Message Types]:https://docs.nodinite.com/repository-model/message-types/overview/
[min]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/min/
[notEqual]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/logical/notequal/
[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/
[regexGroup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/regexgroup/
[removebom]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/removebom/
[replace]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/replace/
[replaceregex]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/replaceregex/
[round]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/round/
[Search Field Expressions]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/overview/
[Search Field Wizard]:https://docs.nodinite.com/administration/log-management/search-fields/getting-started/how-to-use-the-search-field-wizard/
[Search Fields]:https://docs.nodinite.com/administration/log-management/search-fields/features/what-is-a-search-field/
[sqllookup]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/sqllookup/
[startsWith]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/logical/startswith/
[substring]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/alter/substring/
[sum]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/math/sum/
[Test Your Expression]:https://docs.nodinite.com/administration/log-management/search-fields/features/add-or-manage-search-field/#test-your-expression
[toLowerCase]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/tolowercase/
[toUpperCase]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/convert/touppercase/
[xPath]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath/
[XPath plugin]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/xpath/
[xPath2]:https://docs.nodinite.com/administration/log-management/search-fields/features/search-field-expressions/formula/extract/xpath2/