Linx Main Linx Help

Expression Editor Cheat Sheet

Officially the Expression Editor in Linx is to:

“Write expressions using c#. Use this editor to refer to other variables in the process, do calculations, use System provided values, format dates or numbers etc.” - from the Linx Help

But it really is more than that, and will become one of your most treasured tools as you use Linx. In this tutorial we’ll list things you can do with the Expression Editor and show the results.

Where do you find it? On any property that could take in a text value, calculation, True/False etc, you can select the drop-down and choose the Expression Editor:

The Expression Editor itself then opens, and consists of an “Expression” text area, a list of “Variables and functions” and a “Help” box giving information on the functions provided:

Working with Text

Quotes

The Expression Editor interprets the items within it as separate objects or types. Thus when you’d like to work on a piece of text, you always need to show it in quotes: “”.

For example if you write:

This is text

you’ll receive a validation error and the solution will not compile:

The correct way to write will be:

"This is text"

Result:

This is text

If for some reason you want to show the actual quote marks “” you’ll need to use the backslash:

"This \" is a quotation mark"

Result:

This " is a quotation mark

Very important, when writing SQL queries you need to use a single quote ’ for text values:

"SELECT 'Text in quotes'"

Result:

SELECT ‘Text in quotes’

Text manipulation

Working with text couldn’t be easier. The expression editor will handle most of the converting of objects into their text values in the background. Unless you want specific formats, you can simply add the object. To add different pieces of text you use +. For more specialised formatting, use the functions provided.

Appending text:

"This is " + "a sentence."

Result:

This is a sentence.

Appending text to a number:

"There were " + 3 + " little pigs."

Result:

There were 3 little pigs.

Adding a line break:
In the Expression Editor, a line break can be made by dragging the “New Line” function from the provided System functions:

Very important! Remember the + before and after the function you add.

"This is the first line" + $.System.NewLine + "This is the second line"

Result:

This is the first line
This is the second line

Adding another object:
Using simple drag and drop you can pull any result from a previous control in the process into your expression:

"Greetings " + ExecuteSQL1.ForEachRow.ContactTitle + " " + ExecuteSQL1.ForEachRow.ContactName + " from " + ExecuteSQL1.ForEachRow.CompanyName

Result:

Greetings Mr Alex Smith from ACME

Changing text using functions
Linx provides a complete list of functions to assist you in changing your strings.

To use these functions you can just drag and drop them next to your string:

String1.Substring(2,4)

or

"ABCDEFGHIJ".Substring(2,4)

Result:

CDEF

Getting numerical values from strings:
In a lot of occasions your data will give you a text value, but you’d want to change it to a numerical value. The example below shows what happens when two texts with numbers in them are added:

"10.2" + "5.4"

Result:

10.25.4

To get the correct answer, we need to convert these strings to numbers:

"10.2".ToDecimal() + "5.4".ToDecimal()

Result:

15.6

Working with numbers

In most Linx solutions, the Expression Editor is where you’ll be doing your calculations. The most important aspect is to keep in mind the type of numbers you are working with. The different types includes Integers, Decimals, Doubles. If you’re busy with an expression using Integers, the result of the expression will be an Integer. But as soon as you add a Decimal, the result will change to a Decimal value.

Calculations
Using the +, -, /, * symbols, you can perform the basic arithmetic straight unto the numbers. Please note that the standard arithmetic principles apply. Thus the 2 * 5 will occur before subtracted from the 10 + 5.

10 + 5 - 2 * 5

Result:

5

You can also use brackets to group numbers:

(10 + 5 - 2) * 5

Result:

65

Using variables within calculations
As with the text, you can drag any previous result from your process into your expression. Just keep in mind what type it is.

ExecuteSQL1.ForEachRow.Quantity * ExecuteSQL1.ForEachRow.UnitPrice

Result:

100.00

Working with Dates

A Date object contains a date and a time. The Expression Editor provides functions to convert a Date to a String and a String to a Date. There is also a CurrentDateTime system variable that returns the system’s current date and time.

Convert a Date to a String:
You can display a Date as a text value in any format you’d like, and you may decide to exclude the time, or date etc.

$.System.CurrentDateTime.ToString("ddd, yyyy-MM-dd HH:mm:ss")

Result:

Wed, 2015-05-13 10:07:19

Convert a String to a Date:

"2015-05-13".ToDateTime("yyyy-MM-dd")

Result: