- Print
- PDF
The Expression editor can be used to build expressions. These can range from simple expressions, such as hard-coded values to more complex expressions that integrate functions and use logic.
Expressions return a value, and the type of value can vary depending on how the expression is being used. Some examples of different values an expression can return are a number result from a calculation, a string value from a table, a 0 or 1 for a condition, and much more.
Expressions can be used in multiple places within the Lasernet FO Connector, including, but not limited to, the report Structure, Conditions, and individual fields with the toolbox icon. The following are some of the fields within the Report settings fast tabs that include the toolbox icon. Click this icon to open the Expression editor.
The Expression editor is resizable.
Overview
The Expression editor interface consists of a Syntax editor section, an Available functions section on the lower left-hand side with additional information, and testing functions available on the lower right-hand side.
Syntax Editor
The Syntax editor is the place where the expression is written and automatically validated.
The Syntax editor supports the following:
Allows fast typing while catching up with syntax analysis in the background
Automatic parallel syntax analysis and colors on expression segments
String values can be within single or double quotes
Multi-line expressions
Switch–case
An autocomplete list when typing
Automatic validation while typing
Error position reporting with a callout indicating the exact place of error
Enums can be used as value sources
The syntax editor area is resizable
Comments
Available Functions
The Available functions section has useful options that can be used to build the expression.
More information on the options under Available functions is available on the left-hand side.
Value
The Value options under the Available functions section are typically tables associated with the current report.
Selecting a table from the Value menu will populate the Select value field on the right-hand side of the Expression editor. The dropdown can be used to choose a field from the selected table.
Selecting a field for a table in the Select value field will insert the table and field into the Syntax editor. Additional information on the selected table and field can be found beneath Select value. In the following example, field CustConfirmJour.ConfirmId has a Base Type: String and a Type name: ConfirmId.
The Remove button can be used to clear the selected object in the Syntax editor.
Using Clear will clear any selection in the Select value field.
Using the dropdown menu on Select value shows all the available tables for the report, as well as additional functions that can inserted into the expression such as Aggregate, Calculated, Convert, Enums, Forms, Label, LanguageText, Parameter, ReportValue, SubReport, Value, and more.
Value represents a string value and can be used to insert free text into the expression. This may be useful if you want your expression to output a phrase.
Reserved
The Reserved options are reserved values such as names of functions (“if” and “Switch”) or symbols (for example, */ or ()).
When a Reserved function is selected, a description appears on the right-hand side. The Insert button can be used to insert the reserved function into the Syntax editor.
Once the reserved function is inserted, each argument can be selected and modified by either using the Select value or typing directly into the Syntax editor. The underline shows which argument is currently selected in the expression.
Delete all can be used to clear an entire expression with multiple arguments.
Operator
The Operator options are operators that can be used to calculate values.
The following is an example where the CustConfirmJour.SumTax and CustConfirmJour.ConfirmAmount are added together using an operator.
Predefined Functions
The Predefined functions provide the option to add functions (methods) from UI from the existing application (AOT) without any need to customize. It is useful when manipulating functions related to date, for example, finding the first date in a quarter or the end date of a quarter or a year, etc.
Several methods already exist in the standard application. For example, the standard Global class contains a lot of useful methods/functions.
As previously mentioned, you can use the right-hand side to find more information on how to use each predefined function. Use Insert to insert the predefined function into the Syntax editor. Use Select value or type directly into the Syntax editor to modify the arguments of your predefined function.
Test with values can be used to test the expression using values from the system.
In the following example, predefined function wkOfYr calculates the week of the year that a date falls in, according to the ISO 8601 specification. Field CustConfirmJour.ConfirmDate was used as the argument for this function. The Value dropdown in the Test with values section was used to select a confirmation date that exists in the system.
Selecting Calculate test result shows the result of the wkOfYr function on a confirmation date of 2023-10-17 is 42.
Add System Function
It is possible to add and reuse methods from standard the Dynamics 365 for Finance and Operations application. To this end, select and add methods from either the tables or from the classes by using the Add system function option.
You are able to select the Object type, Class name, Method name, and provide a brief description.
Once you click OK, a new menu is created under Available functions, and the new function/method is added under it. In this example, a Global menu was created because the Global Class name was used.
The newly created method can now be used.
To delete any created method or function, select Expression function in the General tab of the Lasernet parameters page (Lasernet > Setup > Parameters). This location is used to avoid accidental deletion of a method or function by an end user.
Expression Editor Features
Expression Typing and Auto-Complete
The auto-complete function will show up as soon as you start typing in the Expression editor. It will automatically filter values based on the context of the expression and what has been already typed.
Images on auto-complete lookup will indicate types of available objects.
General | Description |
---|---|
Value source | |
Enum | |
Function/method | |
Table | |
Operator or reserved word, such as (IF, THEN, SWITCH) |
Fields | Description |
---|---|
Container field | |
Date field | |
Enum field | |
Integer field | |
Real field | |
String field |
If you start typing C, the editor will automatically show all available sources starting with “C”. CustConfirmJour and CustConfirmTrans are the tables that are available for the report and, in this example, the SalesConfirmReplacement is used.
If you select or type the table name and continue typing the field name, all available fields and methods will appear in an auto-complete list.
Error Reporting
Syntax analysis and error reporting are automatic. If there is an error in the expression, an automatic callout with a short error message will appear, and a longer version will appear in the status line below the editor.
Note
The error position in the status line indicated with <-!->.
Syntax
Multi-line expressions are supported. Comments are also supported to improve the documentation of some of the expression parts. For example:
Syntax Colors
Syntax elements are color-coded:
Syntax Highlights | Description |
---|---|
Blue is reserved for operators and reserved words. | |
Dark green is for complete value segments. | |
Dark red is for string constants or numeric constants. | |
Light green is for comments. | |
Bright red is for incomplete values. Complete expressions should not contain these. | |
Regardless of color, underlined segment is Active. Value for such segment will also be editable in a separate value field located below: |
Be aware that syntax highlighting can be slow in environments where network latency is high. Because of automatic validation and highlighting, a few roundtrips to the server and back are required. You can monitor latency in your browser by navigating to F12 > Network.
An established VPN connection can also slow the performance as the latency can get higher compared to running the software without a VPN.
Enums
The value source called Enums is supported. Enums will also appear in the auto-complete lookup, but only when the filter reduces the number of them below 20. This is done to avoid loading a massive amount of data, as there are many Enums in the system.
Enums support three types of values. For example, if SalesTable.Sales status is Open order:
(New) SalesTable.SalesStatus would return the numeric value of the Enum such as 1.
SalesTable.SalesStatus:NAME would return a symbolic representation of the Enum, such as Backorder.
SalesTable.SalesStatus:LABEL would return the label of the Enum, such as Open order.
If these are used in expressions, ensure that you compare the same type of value. Best practice is to use :NAME as this will be the same across all environments, even where numeric values might differ.
Auto-complete also works with Enum values:
Expression Testing
Functionalities for testing expressions are supported. You can test expressions with different values that can be plugged into the expression and observe the output result. To test your expression, specify the test values, then click Calculate test result.
All test values are saved as LastValues in the user’s Usage data under Class > LACExpressionParser > TestValues. The Calculate test result checkmark is also saved in Usage data as Form > LACExpressionEditor > CalculateTestResult. Normally test values can be reused across various expressions, as these are common for all of them. Only relevant values are shown by default, but you can show all test values saved for the user by clicking Show all. Select Clean test values to indicate how many test values are saved for a user.
If the calculation fails, you will get the following test error:
In this case, the expression is technically valid but comparing an integer Enum value with a string produces a testing runtime error.
Examples - How to Write Expressions
Combine Text with Dynamics 365 Fields in Expressions
Navigate to the report's Structure and follow these steps to combine text with Dynamics 365 fields in expressions:
Click the New button to create a new field. This must be done after selecting where you wish this new field to be placed in the XML (in this case SalesInvoiceHeaderFooterTmp).
Give the new field a name.
In the Expression column, click the dropdown button and select Expression.
Layout Text "Invoice Id - Invoice#" with Actual Invoice Number in Dynamics 365
In the Expression column, click the dropdown button, select Value, and type in the text "Invoice Id".
Click out of the box: the value should move to the Expression box at the top.
Click the dropdown button.
To add a second value ("-"), follow the same procedure:
In the Expression column, click the dropdown button, select Value, and type in the text "-".
Click out of the box: the value should move to the Expression box at the top.
Click the dropdown button.
To add the Invoice number from Dynamics 365, follow these steps:
In the Expression column, click the + button, select Table, and then select field.
Click Insert: the value should move to the Expression box at the top.
Click OK.
Show Only a Part of the Text in the String/If Field
Hide Line Field if Line Field is the Same as a Header Field
This example is carried out on a Sales Confirmation report, where we have a delivery date on the line level and on the header level.
On line level, we only want to show those dates that are different from the header date.
Follow these steps:
Find the line field on the Condition column, and choose Code.
Click the Edit button.
In the Expression definition box, paste in the following expression: If SalesTable.DeliveryDate=SalesConfirmDetailsTmp.DlvDate Then 0 Else 1, and click OK.
Header:
Before:
After - No line field when the line field is the same as the header field:
Show Only a Limited Part of the Substring - Expression: If SalesTable.ShippingDateRequested=SalesLine.ShippingDateRequested Then 0 Else 1
The following example illustrates how to create a substring for a Purchase Order (Purch-Id). The number sequence is six characters, and we only want to show three on the report. Follow these steps:
Create a new element by clicking the dropdown button.
Paste in the following expression: SubString ( PurchPurchaseOrderHeader.PurchId , 1 , StrLength ( PurchPurchaseOrderHeader.PurchId ) - 3 )
The result is that the newly created element is 000.
Show One or Zero if "CFR,CIF,CIP,CPT,DAT,DAP,DDP" Contains DlvTerm_Terms.Code
In this example, we want to return one when true and zero when false if our delivery term contains CFR,CIF,CIP,CPT,DAT,DAP, and DDP.
Expression: "CFR,CIF,CIP,CPT,DAT,DAP,DDP" Contains DlvTerm_Terms.Code
This will return one if true and zero if false, without the need for the If Else statement.
Replace a Word with Another Word
Some companies use the Proforma invoice or Sales Confirmation as the Export Invoice. Therefore, they want the title "Export invoice" to replace the title.
Paste or build the following expression: strReplace ( SalesConfirmHeaderTmp.LACOriginalReport_DocumentTitle() , "Confirmation" , "Export Invoice" )
Result:
Calculate: Diving
In this example, the LineAmount divided by Qty can show the "unit price after discount".
To do so, create a new element by clicking the + button and paste in the following expression: SalesConfirmDetailsTmp.LineAmount/SalesConfirmDetailsTmp.Qty.
Result: