Skip to content

Expressions

Expressions in MECEAP are a way of calculating field values by using conditions and fields in the document

Functions

There are some functions available to use in the expressions, below we will give an example of use of each function based on the document:

DocumentName: Purchase
Fields:
* summary (Text)
* description (Text)
* creationDate (DateTime)
* supplier (Text)
* items (List) 
    * product
    * quantity
    * price

Sum

Returns the sum of all the values, SUM can be used with numeric columns only

Syntax

  • sum(${itemList.total})

Add

Returns the sum of all the values, add can be used with numeric and datetime columns only

Syntax

  • 5+5 (10)
  • ${price}+5
  • ${creationDate} + 1
  • "2019-05-13" + 1 (2019-05-14)
  • add("2019-05-13", 5, weekday) (2019-05-20)
  • add(${date}, ${days}, weekday)
  • add(${days}, ${date}, weekday)
  • add(${date}, ${number}, week)
  • add(${date}, ${number}, month)
  • add(${date}, ${number}, year)

In the third parameter can be used minute, hour, day, weekday, week, month, year

When the expression use WD only week days will be added in the start date

Subtract

Returns the subtraction of all the values, subtract can be used with numeric and datetime columns only

Syntax

  • 5-2 (3)
  • ${price}-5
  • ${creationDate} - 1
  • "2019-05-13" - 1 (2019-05-12)
  • subtract("2019-05-13", 5, weekday) (2019-05-06)
  • subtract(${date}, ${days}, weekday)
  • subtract(${days}, ${date}, weekday)
  • subtract(${date}, ${number}, week)
  • subtract(${date}, ${number}, month)
  • subtract(${date}, ${number}, year)

In the third parameter can be used minute, hour, day, weekday, week, month, year

When the expression use WD only week days will be added in the start date

Max

Returns the maximum value in the expression

Syntax

  • max(${itemList.price})

Min

Returns the minimum value in the expression

Syntax

  • min(${itemList.price})

Avg

This function returns the average of the values in a group

Syntax

  • avg(${itemList.total})

Count

This function returns the number of items found in a group

Syntax

  • count(${itemList.price})

Concat

Add two strings together

Syntax

  • concat(${summary}, ${description})
  • concat("a", "b") result = "ab"

Contains

Is used within another function to indicate whether or not a string(searchString) is present inside the source string(sourceString).

Syntax

  • contains(${summary}, ${description})
  • contains("sourceString", "searchString")

  • Example:

  • contains("Mercado Eletronico", "Mer") result = true
  • contains("Mercado Eletronico", "MER") result = false
  • contains(upperCase("Mercado Eletronico"), "MER") result = true
  • if(contains("Mercado Eletronico", "MER"), 1, 0) result = 0

UpperCase

Converts all the alphabetic characters in a string to uppercase.

Syntax

upperCase(str)

  • Example:
  • upperCase("Mercado Eletronico") = MERCADO ELETRONICO

Substr

Returns the part of the String between the start and end.

Syntax

substr(str, start, end)

  • Example:
  • Description = Master substr(${description}, 0, 2) = Mas

Replace

This function replace all occurrences of a String(searchString) within another String(toBeReplaced).

Syntax

replace(toBeReplaced, searchString, replacement)

  • Example:
  • replace (${summary}, ${description}, ${supplier})
  • Price = 3.14 replace(${price}, ".", comma) = 3,14

If

Imposes conditions on the execution of a statement

Syntax

  • if(${quantity} >= 3, 0, 1)
  • if(Boolean_expression, do if true, do if false)
  • if((${quantity}*${price})>30, 0, 1)
  • if((2*(${quantity}*${price})/2)>30, 0, 1)
  • if((2*(${quantity}*${price})/2)>(30), 0, 1)
  • if((2*(${quantity}*${price})/2)>(30*2), 0, 1)
  • if((2+sum(${quantity},${price})/2)>30, 0, 1)

DateDiff

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate

The field type receiving value must be Integer

Syntax

dateDiff(startDate, endDate, datepart)

  • Examples:
  • dateDiff(${creationdate}, now, minute)
  • dateDiff(${creationdate}, now, hour)
  • dateDiff(${creationdate}, now, day)
  • dateDiff(${creationdate}, now, week)
  • dateDiff(${creationdate}, now, month)
  • dateDiff(${creationdate}, now, year)
  • dateDiff(${creationdate}, now, weekday)

DateMin

This function returns the smallest DateTime between of specified DateTime array (Java Spread Operator).

*The field type receiving value must be DateTime

Syntax

dateMin(...args)

  • Examples:
  • dateMin(${dateFieldOne}, ${dateFieldTwo}, ${dateFieldThree})
  • dateMin(${dateFieldOne}, now, ${dateFieldTwo})

DateMax

This function returns the largest DateTime between of specified DateTime array (Java Spread Operator).

*The field type receiving value must be DateTime

Syntax

dateMax(...args)

  • Examples:
  • dateMax(${dateFieldOne}, ${dateFieldTwo}, ${dateFieldThree})
  • dateMax(${dateFieldOne}, now, ${dateFieldTwo})

Round

This function returns the specifies rounding for numeric operations capable of dropping and incrementing precision.

Each rounding mode indicates how the least significant returned digit of a rounded result should be calculated.

*The field type that receives the value must be String or Decimal (In the field details table in more options, the Decimal Places must be equal to the scale of the 'second parameter of the expression', otherwise, when saving the document, it may cause unexpected errors)

Modes

FLOOR: Default rounding mode to round towards negative infinity (If the result is positive). This rounding mode never increases the calculated value.

CEILING: Rounding mode to round towards positive infinity (if the result is positive). This rounding mode never decreases the calculated value.

HALF_UP: Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant. Behaves as for CEILING mode, if the discarded fraction is ≥ 0.5, otherwise, behaves as for defaul mode. *Note that this is the rounding mode commonly taught at school.

HALF_DOWN: Rounding mode to round towards "nearest neighbor" unless both neighbors are equidistant, in which case round down. Behaves as for HALF_UP if the discarded fraction is > 0.5.

HALF_EVEN: Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for HALF_UP if the digit to the left of the discarded fraction is odd. Behaves as for HALF_DOWN if it's even. Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as "Banker's rounding," and is chiefly used in the USA.

Syntax

round(${value}, 2, "FLOOR|CEILING|HALF_UP|HALF_DOWN|HALF_EVEN")

  • Examples:
  • round(1.1199, 2) (1.11)
  • round(1.1999, 2) (1.19)
  • round(1.12, 2, "CEILING") (1.13)
  • round(1.5, 0 "HALF_UP") (2)

  • round(1.5, 0, "HALF_DOWN") (1)
  • round(1.5, 0, "HALF_EVEN") (2)