- 3 minutes to read

Formula - Min

TIP: An example of real-life usage, use the Min function to get an alert if an order in a batch has an amount field less than X.

The Min( ) Formula function is a pretty straight-forward and self-explanatory function. It is used to return the Min value extracted from the Content part.

Quick example

Let's get you started with the following example. For other and more advanced examples, scroll down on this page to the Examples section.

Input Expression Result

<ns0:Orders xmlns:ns0="SupplyChain.Schemas/1.0">
  <Order>
    <Id>1337</Id>
    <Amount>666</Amount>
    <City>Grums</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
    <Order>
    <Id>1338</Id>
    <Amount>42</Amount>
    <City>Karlstad</City>
    <Partner>QWNtZQ==</Partner>
  </Order>
 </ns0:Orders>



 Min(xpath('Orders/Order/Amount', body))


42
Text Data Min expression Unique values

Features

The Min( ) function can be used on any content, as long as data is a numerical value returned from the Content part. It doesn't matter if the content parameter a plain text or any valid Formula Plugin function. Please notice that the number returned represents the Min of the set of extracted values; more on this later below.

  • Return the Min value from extracted values from the Content.
  • It returns the Min of the unique values from Content
  • It can be applied on the Content part that returns data; Like jsonpath, xpath functions or even a plain-text, review the Formula user guide for the complete list of functions.

This plugin loads the entire message into RAM, so make sure to apply this function only on small messages..

How to use

The Content part should contain numerical data to use the Min function, (otherwise, it will fail, and you will end up with nothing as the result). But first and foremost, you must configure the Formula plugin:

  • Select Formula as expression type plugin.
  • Write down the expression to use in the 'Expression' text area.
  • Input Content as a parameter to the function.

Syntax

Use the Min function with any of the following parameters:

  • From Message Body: Min(body, [bool unique = true])

  • From Message Context: Min(context('MessageContextKey'), [bool unique = true])

  • Result from previous Formula operation Min(SomeOtherNestedFormulaFunction(Content), [bool unique = true])

Examples

Below, you will find different common examples of how to use the Min function.

Body as Content

What value is the smallest?

"{a:[{b:'1337'},{b:'8'},{b:'42'}]}" is the message body text; By using the provided expression, the result is 8.

e.g. Min(value)

simpleBody

Message Body


{a:[{b:'1337'},{b:'8'},{b:'42'}]}

Expression


Min(jsonpath('a[*].b', body))


Context as Content

What is the Min id from a CSV formatted collection?

The Message context value is csv content(!), with a comma "," delimiter where the key is "Ids", by using provided expression, the result is 10.

csv_MessageContext

Message Context value Body


"face","suit","value"
"king","spades","13"
"queen","spades2","12"
#"jack","spades3","666"
"ten","spades4","10"

Expression


Min(csv(1,',',2,'#',context('Ids')))


Next Step

How to Add or manage Search Fields
How to Add or manage Log Views

Expression Type Plugins are used in Search Fields
What are Search Fields?
What are Search Field Expressions?
What are Message Types?
What are Log Views?