# Expression Editor

***

## Quick Start

{% embed url="<https://youtu.be/Rprsw-tMX3s>" %}

***

## What is the Expression Editor?

The Expression Editor is available in the dropdown of all properties that accept [expressions](/main-concepts/expressions.md).

<figure><img src="/files/twpOUOZBu9Bj6oLVxM0M" alt="The Expression Editor Interface"><figcaption><p>The Expression Editor Interface</p></figcaption></figure>

1. Click to open the Expression Editor
2. System variables that are always available to include in an expression
3. Functions that are available to include in an expression
4. Variables that are in scope, and available to include in an expression
5. The expression
6. Help on a selected function. (To view help content, click on the relevant function in the drop-down list)

***

## Layout of the Expression Editor

<figure><img src="/files/k26LPPKerD4tJZfO62rJ" alt="Expression Editor Layout"><figcaption><p>Expression Editor Layout</p></figcaption></figure>

The Expression Editor is composed of the following:

### Expression area

Enter an expression or select relevant variables and functions from the available lists to build up an expression.

### Variables and Functions

#### Variables folder

There are 2 categories of variables available to include in an expression:

1. In-scope variables: Those variables that you have already created upstream within the same function for which you are creating an expression.
2. Those variables you have already created as Settings.

<figure><img src="/files/snwO2uQyEAOQ91kjJUQ3" alt="Expression Editor Variables"><figcaption><p>Expression Editor Variables</p></figcaption></figure>

#### System folder

The System folder includes system properties and functions.

1. System properties
   * `CurrentDateTime`
   * `NewLine`
   * `Null`
2. Functions

### Function Help

<figure><img src="/files/Kcs2Gq3ppJgIqp6xjTd5" alt="Function Help"><figcaption><p>Function Help</p></figcaption></figure>

To view help for a specific function, click on it where it is listed. The Help for the selected function is displayed in the help section.

### Test

<figure><img src="/files/98iK0NpoeC3EvclOASyB" alt="Variables and Functions Test"><figcaption><p>Variables and Functions Test</p></figcaption></figure>

To test an expression for correct structure and syntax:

* Click on the Test tab
* Click the Run Test button
* The result of the test is displayed

A typical error message is: “Expression contains invalid syntax.”

**Note:** When testing an expression, usually relevant input has to be provided by the user. If the expression references a result from a function above, a value needs to be provided that will substitute the result in the expression. The test will be executed with that value. If my expression is `Integer1 + Integer2`, then the user will be asked to provide two integers in the test tab for the test.

***

## Working with Expressions

Linx uses C# expressions to evaluate values at run time.

### Concept

Excel uses expressions in cells. These expressions evaluate to a single value visible in the cell. In a similar fashion, Linx uses expressions when assigning values to properties. Linx expressions are evaluated at run time. Excel expressions use VBA syntax. Linx expressions use C# syntax. Linx expressions in property windows are preceded by a "=".

<figure><img src="/files/9u61Lm6bE2Wod8Oo8BkC" alt="Simple Expression"><figcaption><p>Simple Expression</p></figcaption></figure>

1. `=` indicates that this is an expression
2. Click here to open the Expression Editor
3. Variables available to include in the expression
4. Variable that is being configured

### Definition

An expression is a series of operands and 0 or more operators that evaluates to a single value.

#### Operand

Operands can be values, names, or functions.

* *Values* are numbers or strings e.g. `123`, `"abc"`. Strings are enclosed in double quotes.
* *Names* refer to variables available in the scope of the expression e.g. `amount + 1` will add `1` to a variable called `amount` and return the result. Properties of variables are referred to using dot notation, e.g. `Person.Age + 1` will add `1` to `Person.Age` and return the result.
* *Functions* are operations that can be performed on another operand e.g. `Person.Birthdate.ToString("yyyy-MM-dd")` will return `Person.Birthdate` as a string formatted to look like `"2016-12-31"`. Functions can be strung together e.g. `" 123,45 ".Trim().Replace(",",".")` will return `123.45`.

### Operators

| Operator | Description           |
| -------- | --------------------- |
| +        | Add, Concatenate      |
| -        | Subtract              |
| \*       | Multiply              |
| /        | Divide                |
| <        | Less than             |
| <=       | Less than or equal    |
| >        | Greater than          |
| >=       | Greater than or equal |
| ==       | Equal                 |
| !=       | Not Equal             |
| &&       | And                   |
| \|\|     | Or                    |

For a full list of C# operators, go [here](https://msdn.microsoft.com/en-us/library/ms173145.aspx). Linx does not support all the operators.

***

## Things You Can Do

### String Concatenation

Strings are concatenated using `+`, e.g. `"ab" + "c"` evaluates to `"abc"`. Build a CSV line with an expression like `Person.Name + "," + Person.Surname + $.System.NewLine`.

When strings are mixed with numbers, the numbers are added until the first string is encountered. Thereafter, operands are concatenated, e.g.

`"1" + 2 + 3 + 4` will evaluate to `"1234"`.

`1 + 2 + "3" + 4` will evaluate to `"334"`.

### String Manipulation

Use functions like `SubString`, `Trim`, `ToUpper`, `Split`, etc. to work with string variables, e.g. `TextFileRead1.FileContents.Replace("John", "Peter")` will replace all instances of `"John"` in the `FileContents` variable with `"Peter"`.

### String Formatting

Use `FormatWith` to create a string from several different inputs. The above CSV sample can be built as `"{0},{1}{2}".FormatWith(Person.Name, Person.Surname, $.System.NewLine)`.

The numbers inside curly braces refer to the index of the parameter in the `FormatWith` part. For larger string formatting jobs, rather use a templating function like [RazorTemplateTransform](/reference/plugins/text/content/razortemplatetransform.md).

### Calculations

e.g. `AmountExVat * (1 + VatRate)`

### Date Operations

Format a date: `Person.Birthdate.ToString("yyyy-MM-dd")`

Return the month: `Person.Birthdate.Month`

### Boolean Expressions

In properties where `true` or `false` are expected, the expression must return a boolean value, e.g.

`Person.Name == "Mary"` (name is Mary)

`Person.Age < 10 && Amount > 500` (person is younger than 10 and amount is greater than 500)

{% hint style="warning" %}
Important

A Linx boolean type can only be populated with `true` or `false` (all letters in lower case). It does not accept any other value or variation of true/false like Y/N, Yes/No, 1/0, on/off, TRUE/FALSE or True/False.

Example:\
When using the Expression Editor to check the value of a boolean, for example in an IfElse function:\
`Boolean == false`.
{% endhint %}

***

## Functions

Functions in an expression are operations that can be performed on data. Different functions apply to different types of data.

Go [here](/reference/designer/expressioneditorfunctions.md) for a list of functions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.linx.software/reference/designer/expression-editor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
