What are the Expressions?


Expressions in Linnworks is a way of outputting data from the system based on a mathematical or functional expressions. This functionality applies to printing functions (printing invoices, labels), generating emails, running macro scripts and data export/import automation.

For example if you wanted to create a new field on an invoice which will contain some calculated value you can use Output Formula Value in the text field in the Report Designer and code the expression to output the desired result.
Lets look at some examples:

Examples

Show calculated tax (VAT) on the invoice by adding 18% of the Order Total to the total order value

  • Create a text field on the report
  • Go to properties and enter the following expression in to the Output Formula Value


N2[OrderTotal + (OrderTotal  - (OrderTotal * 0.18))]

where OrderTotal is a variable available in the report, N2 is a money conversion function

You can also hide objects on the invoice based on the expression

  • Create an image on the invoice
  • Change the properly of the Visibility Condition field to be an expression

Country = ”United States” or Country = “Canada” or Country=”United Kingdom”

the image will only be show if the customer country is one of the listed above.

You want to print shipping tracking number in the email only if it exists

  • Open email template (Order Dispatched type)
  • Enter the following code somewhere in the emai

iif[Order.PostalTrackingNumber!=””,”Postage Tracking Number”,””]: [{Order.PostalTrackingNumber}]

Similarly you can do expression evaluation in the email template, macros, postage label and data imports/exports.

If you have any problems creating expressions please post any questions on the forum, we will be able to help out.

Function syntax

Average
avg[p1, ..., pn] where p1,...,pn can be converted to doubles.
Calculates the average of a list of numbers. The list items must be able to convert to doubles.

Absolute Value
abs[p1] where p1 can be converted to a double.
Calculates the absolute value of a numeric parameter.

If-else-end
iif[c, a, b] where c is the condition and must evaluate to a Boolean. The value a is returned if c is true, otherwise, the value b is returned.
Performs an if-else-end

Lower Case
 LCase[a]
Converts a string to lower case

Left
left[s, n] where s is the string and n is the number of characters
Returns the left number of characters from a string parameter.

Length
 len[a] where a is a string variable
Returns the length of a string

Median
 mid[p1, ..., pn] where p1, ..., pn are numeric values
Calculates the median for a list of numbers

Right
 right[s, n] where s is the string and n is the number of characters.
Returns the right number of characters from a string parameter

Round
round[n, d] where n is the numeric value to be rounded, and d is the number of decimal places.
Rounds a numeric value to the number of decimal places

Square Root
sqrt[a] where a is a numeric parameter
Calculates the square root of a number.

Upper Case
 ucase[a]
Converts a string to upper case

Is Null or Empty
IsNullOrEmpty[a]
Indicates is the parameter is null or empty.

Is True or Null
isTrueorNull[a]
Indicates if the parameter has the value true or is null;

Is False or Null
IsFalseOrNull[a]
Indicates if the parameter has the value false or is null

Trim
trim[a]
Trims the spaces from the entire string

Right Trim
rtrim[a]
Trims the spaces from the right of a string

Left Trim
 ltrim[a]
Trims the spaces from the left of a string

Date Add
 dateadd[date, "type", amount] where date is a valid date, and type is "y", "m", "d" or "b" (representing year, month, day, or business days) and amount is an integer
Adds an amount to a date. Please note that the amount may be negative.

Concatenation
concat[p1, ..., pn]
This operand function concatenates the parameters together to make a string.

Date
date[m, d, y] where m is an integer and is the month, d is an integer and is the day, and y is an integer and is the year
Create a new date data type

Right Pad
 rpad[a, b, n] where a and b are string values and n is numeric. The parameter p will be appended to the right of parameter a, n times.
Pads a string on the right with new values

Left Pad
lpad[a, b, n] where a and b are string values and n is numeric. The parameter p will be appended to the left of parameter a, n times.
Pads a string on the left with new values

Join
join[a, b1, ..., bn] where a is the delimiter and b1, ..., bn are the items to be joined.
Joins a list of items together using a delimiter

Search String
 SearchString[a, n, b] where a is the string that is being searched, b is the string that is being sought, and n is the start position in a
Searches for a string within another string at a specified starting position

Day
day[d1] where d1 is a date value
Returns the day of a date

Month
month[d1] where d1 is a date value
Returns the month of a date

Year
year[d1] where d1 is a date
Returns the year of a date

Sub String
SubString[s, a, b] where s is the string, a is the starting point, and b is the number of characters extracted.
Extracts a substring from a string

Numeric Max
NumericMax[p1, ..., pn]
Finds the maximum numeric value in a list

Numeric Min
NumericMin[p1, ..., pn]
Finds the numeric minimum value in a list

Date Max
 datemax[d1, ..., dn] where d1, ..., dn are dates
Returns the maximum date in the list

Date Min
 datemin[d1, ..., dn] where d1, ..., dn are dates.
Returns the minimum date in the list.

String Max
 StringMax[p1, ..., pn]
Finds the maximum string in the list

String Min
 StringMin[p1, ..., pn]
Finds the minimum string in the list

Contains
contains[p1, p2, ...., pn] If p1 is in the list p2, ..., pn, this function returns "true" otherwise, this function returns "false".
Indicates if the item is contained in the list.

Between
 between[var, val1, val2] where var, val1, and val2 are integers. if var >= val1 and var <= val2 then the function returns "true", otherwise, the function return "false".
Indicates if a value is between the other values. Please note that the comparison is inclusive.

Index Of
 indexof[a, b1, ..., bn] If the list b1, ..., bn contains the value a, the index of the value is returned, otherwise, -1 is returned. Please note that this is zero based indexing
Returns the index of a list item.

Now
now[] This operand function takes no parameters
Returns the current date

Replace
Replace[a, b, c] where a is the search string, b is the value being replaced, and c is the value that is being inserted
Replaces one string with another string

Evaluate
eval[r] where r is any valid Rule Basic string rule
Evaluates a Rule Basic string. I think this is an interesting operand function. In my Rules Engine, I may have rules that return a Rules Basic string. Then the result could be evaluated with this operand function. That is, have rules that create other rules. Example: eval[concat["a:=5;", "b:=6;", "a+b"]]

Remove
remove[a, b] where a and b are string
Removes the specified characters from the string

Double Quote
 quote[]
Returns a double quote

Proper Case
 pcase[a] where a is a string
Converts a string to Proper Case. For example, the proper case of "buFFalo" "Buffalo"

Sin Wave
sin[a]
Calculates the sin of a numberf

Boolean Not
not[a]
Performs a boolean Not operator on the parameter a. For example, Not[true] = false.

Is all digits
IsAllDigits[a]
Returns true/false indicating if the parameter is all digits. For example, IsAllDigits["1234"] = true

Numeric (money)
  N2[a]
Returns numeric value, 2 decimal places. For example N2[100/3] returns 33.33