Skip to content

Expressions ​

Expressions are powerful rules that dictate how the value for each Output Name is generated. The Orisha Commerce Platform (OCP) utilizes the NCalc library for evaluating these expressions, supporting a wide range of mathematical and logical operations.

Variables ​

ParameterDescription
[Name]The name of the item (locale text field, nullable).
[FamilyCode]The family code of the item (text field, nullable).
[ItemCode]The code of the item (text field).
[UomCode]The unit of measure code of the item (text field).
[VatTariff]The VAT tariff of the item (Normal, Low1, Low2, SuperLow, ParkingTariff, NoVat).
[Images]The images of the item (array of objects).
[Stocks]The stocks of the item (array of objects).
[RestockOrders]The restock orders of the item (array of objects).

Attributes ​

You can access an item's attributes using the [Attributes.(...)] accessor, for example [Attributes.OLB-Color]. Attributes can have different types.

When accessing an attribute through an expression, the returned value is always an array. This is because an attribute like materials can hold multiple values (e.g., stone, wood, etc.).

If you only need a single value, you can use the firstOrDefault expression function to retrieve the first one.

📦 any ​

Determines if any items in a list match a condition. If no condition is provided, determines if the list contains any items.

ParameterTypeDescription
list*object[]The list
predicatestringA string to represent the value to be evaluated
lambdastringThe lambda expression

Examples

ExpressionResult
any((1, 2, 3))true
any(())false
any((1, 2, 3), 'x', 'x > 2')true
any((1, 2, 3), 'x', 'x > 3')false

📦 coalescing ​

Returns the first non-null value

ParameterTypeDescription
parameter1*object
parameter2*object
parameter3object
parameter4object
parameter5object
parameter6object
parameter7object
parameter8object
parameter9object
parameter10object

Examples

ExpressionResult
coalescing(null, 'Hello', 'World')'Hello'
coalescing('Hello', 'World')'Hello'

📦 concat ​

Concatenate lists.

ParameterTypeDescription
list1*object[]Collection.
list2*object[]Collection.
list3object[]Additional collections.
list4object[]Additional collections.
list5object[]Additional collections.

Examples

ExpressionResult
concat(list('a', 'b'), list('c'))list('a', 'b', 'c')

📦 contains ​

Determines whether a string contains a specified substring (case-sensitive).

ParameterTypeDescription
input*stringThe original string.
value*stringThe substring to search for.

Examples

ExpressionResult
contains('Hello World', 'World')true
contains('Hello World', 'world')false

📦 count ​

Counts all the elements in the list.

ParameterTypeDescription
list*object[]The original list.

Examples

ExpressionResult
count(list(1, 2, 3))3

📦 displayProperty ​

Returns an object with the specified title and value. The title is a locale value. When the value is null, the function returns null.

ParameterTypeDescription
title*string
value*object

Examples

ExpressionResult
displayProperty('Title', 'Value')Object with title and value
displayProperty('Title', null)Null
displayProperty(multilang('en-US', 'Color'), 'Blue')Object with title and value

📦 distinct ​

Creates a distinct list from the provided collection.

ParameterTypeDescription
list*object[]The original list.

Examples

ExpressionResult
distinct(1, 2, 2)[1, 2]

📦 elementAt ​

Returns the element at the specified index in a collection.

ParameterTypeDescription
collection*object[]The collection to retrieve the element from.
index*System.Int32The index of the element to retrieve.

Examples

ExpressionResult
elementAt([1, 2, 3], 1)2
elementAt(['a', 'b', 'c'], 0)'a'
elementAt([1, 2, 3], 5)null

📦 endsWith ​

Determines whether a string ends with a specified suffix (case-sensitive).

ParameterTypeDescription
input*stringThe original string.
value*stringThe suffix to check for.

Examples

ExpressionResult
endsWith('Hello World', 'World')true
endsWith('Hello World', 'world')false

📦 firstOrDefault ​

Returns the first item in a list or null if the list is empty.

ParameterTypeDescription
list*object[]The original list.

Examples

ExpressionResult
firstOrDefault(list(1, 2, 3))1
firstOrDefault(list())NULL

📦 getProperty ​

Gets a property from an object. Supports nested property paths using dot notation (e.g., "Address.Street"). If the property cannot be found, returns the default value if provided.

ParameterTypeDescription
input*objectThe object to get the property from.
propertyName*stringThe name or path of the property to get (supports dot notation for nested properties).
defaultValueobjectThe default value to return if the property cannot be found.

Examples

ExpressionResult
getProperty(object, "Address.Street")value

📦 iif ​

Returns one of two values depending on the evaluation of a boolean expression.

ParameterTypeDescription
condition*objectThe boolean expression to evaluate.
trueValue*objectThe value to return if the condition is true.
falseValue*objectThe value to return if the condition is false.

Examples

ExpressionResult
iif(1 == 1, 'condition met', 'condition not met')condition met
iif(1 == 2, 'condition met', 'condition not met')condition not met

📦 indexOf ​

Determines the index of the first occurrence of a specified string within a string (case-sensitive).

ParameterTypeDescription
stringValue*stringThe string to search within.
lookupValue*stringThe string to search for.

Examples

ExpressionResult
indexOf('foobar', 'bar')3

📦 join ​

Concatenate elements of a collection into a single string, separated by a specified delimiter.

ParameterTypeDescription
delimiter*stringThe character used to separate elements in a string.
list*object[]Collection of string values.

Examples

ExpressionResult
join('-', list('a', 'b', 'c')a-b-c

📦 lastOrDefault ​

Returns the last item in a list or null if the list is empty.

ParameterTypeDescription
list*object[]The original list.

Examples

ExpressionResult
lastOrDefault(list(1, 2, 3))3
lastOrDefault(list())NULL

📦 length ​

Returns the length of a string.

ParameterTypeDescription
input*stringThe string to get length.

Examples

ExpressionResult
length('text')4
length('')0

📦 list ​

Creates a list from the provided parameters, filtering out null values.

ParameterTypeDescription
list*object[]The original list.

Examples

ExpressionResult
list(1, 2, 3)[1, 2, 3]
list(1, null, 3)[1, 3]

📦 list ​

Creates an empty list

ParameterTypeDescription

Examples

ExpressionResult
list()[]

📦 localeValue ​

Returns the value of a LocaleValue for the specified locale or the default value if the locale is not found.

ParameterTypeDescription
localeValue*objectTranslation object.
localestringThe locale to get the value for.

Examples

ExpressionResult
localeValue([Name], "en-US")Translation in English
localeValue([Name])Default translation

📦 multilang ​

Returns a LocaleValue object with the specified locale and value pairs. First value is the default value.

ParameterTypeDescription
localesAndValues*System.String[]Locale and value pairs, where the first pair is the default value.

Examples

ExpressionResult
multilang('en-US', 'Hello', 'es-ES', 'Hola')LocaleValue with English and Spanish translations
multilang('en-US', 'Hello')LocaleValue with English translation

📦 objectCreate ​

Creates an object with the specified property name-value pairs. Parameters must be provided in pairs: property name, property value.

ParameterTypeDescription
propertyPairs*object[]Property name-value pairs. Must be provided in alternating name, value sequence.

Examples

ExpressionResult
objectCreate('Name', 'John', 'Age', 30){ Name: 'John', Age: 30 }
objectCreate('Street', 'Main St', 'Number', '123'){ Street: 'Main St', Number: '123' }

📦 orderBy ​

Orders a list by a lambda expression.

ParameterTypeDescription
list*object[]The original list
predicate*stringA string to represent the value to be evaluated
lambda*stringThe lambda expression
sortDirectionstring(Optional) The sort direction, either 'asc' or 'desc'. Defaults to 'asc'.

Examples

ExpressionResult
orderBy((3, 2, 1), 'x', 'x')[1, 2, 3]
orderBy((1, 2, 3), 'x', '-x')[3, 2, 1]

📦 parseInt ​

Parses a string to an integer. If the string cannot be parsed, returns the default value if provided.

ParameterTypeDescription
input*stringThe string to parse.
defaultValueint?The default value to return if parsing fails.

Examples

ExpressionResult
parseInt('123')123
parseInt('abc', 0)0

📦 regexGroup ​

Extracts a named group from a string that matches a given regular expression pattern.

ParameterTypeDescription
input*stringThe string to check.
pattern*stringThe regular expression pattern.
index*int?The index of the group to extract.

Examples

ExpressionResult
regexGroup('abc123', '^(?<prefix>[a-z]+)(?<number>[0-9]+)$', 0)abc
regexGroup('abc123', '^(?<prefix>[a-z]+)(?<number>[0-9]+)$', 1)123
regexGroup('abc123', '^(?<prefix>[a-z]+)(?<number>[0-9]+)$')abc

📦 regexIsMatch ​

Checks if a string matches a given regular expression pattern.

ParameterTypeDescription
input*stringThe string to check.
pattern*stringThe regular expression pattern.

Examples

ExpressionResult
regexIsMatch('abc123', '^[a-z]+[0-9]+$')true
regexIsMatch('abc', '^[a-z]+[0-9]+$')false

📦 replace ​

Replaces all occurrences of a specified substring in a string with another substring.

ParameterTypeDescription
value*stringThe original string.
oldValue*stringThe substring to be replaced.
newValue*stringThe substring to replace with.

Examples

ExpressionResult
replace('Hello World', 'World', 'Universe')'Hello Universe'

📦 select ​

Selects items from a list based on a predicate and applies a lambda expression to each item.

ParameterTypeDescription
list*object[]The original list.
predicate*stringThe predicate to evaluate for each item.
lambda*stringThe lambda expression to apply to each item.

Examples

ExpressionResult
select(list(1, 2, 3), 'x', 'x * 2')[2, 4, 6]

📦 skip ​

Skips a specified number of elements from the beginning of a collection and returns the remaining elements.

ParameterTypeDescription
collection*object[]The collection to skip elements from.
count*System.Int32The number of elements to skip.

Examples

ExpressionResult
skip([1, 2, 3, 4, 5], 2)[3, 4, 5]
skip([1, 2], 5)[]

📦 split ​

Divides a string into a list of substrings by specified separator.

ParameterTypeDescription
input*stringInput text to split
separator*stringSeparator

Examples

ExpressionResult
split('Jan,Feb,Mar,Apr', ',')['Jan', 'Feb', 'Mar', 'Apr']

📦 startsWith ​

Determines whether a string starts with a specified prefix (case-sensitive).

ParameterTypeDescription
input*stringThe original string.
value*stringThe prefix to check for.

Examples

ExpressionResult
startsWith('Hello World', 'Hello')true
startsWith('Hello World', 'hello')false

📦 stringIsNullOrEmpty ​

Checks if a string is null or empty.

ParameterTypeDescription
value*stringa value to check if it is null or empty.

Examples

ExpressionResult
stringIsNullOrEmpty(' ')true

📦 substring ​

Extracts a substring from a string starting at the specified index with optional length.

ParameterTypeDescription
input*stringThe original string.
startIndex*System.Int32The starting index (0-based).
lengthint?The number of characters to extract (optional).

Examples

ExpressionResult
substring('Hello World', 0, 5)'Hello'
substring('Hello World', 6)'World'

📦 sum ​

Sums numeric items.

ParameterTypeDescription
list*object[]The original list.

Examples

ExpressionResult
sum(list(1, 2, 3))6

📦 take ​

Takes a specified number of elements from the beginning of a collection.

ParameterTypeDescription
collection*object[]The collection to take elements from.
count*System.Int32The number of elements to take.

Examples

ExpressionResult
take([1, 2, 3, 4, 5], 3)[1, 2, 3]
take([1, 2], 5)[1, 2]

📦 toLower ​

Converts a string to lowercase.

ParameterTypeDescription
value*stringThe original list.

Examples

ExpressionResult
toLower('Hello World')'hello world'

📦 toUpper ​

Converts a string to uppercase.

ParameterTypeDescription
value*stringThe original list.

Examples

ExpressionResult
toUpper('Hello World')'HELLO WORLD'

📦 trim ​

Removes leading and trailing whitespace from a string.

ParameterTypeDescription
input*stringThe string to parse.

Examples

ExpressionResult
trim(' text ')text

📦 where ​

Filters a list based on a predicate and applies a lambda expression to each item.

ParameterTypeDescription
list*object[]The original list.
predicate*stringThe predicate to evaluate for each item.
lambda*stringThe lambda expression to apply to each item.

Examples

ExpressionResult
where(list(1, 2, 3), 'x', 'x > 1')[2, 3]