Skip to main content

The expression editor

An expression is a formula that calculates a value: the result of an operation on fields, a composed text, or a condition that is true or false. You use it to fill the text of a control, to calculate a calculated field, and in a condition that hides a control or changes its color. You write it by hand or build it in the Expression Editor. This page is for implementers and support staff who build templates.

Opening the editor​

The editor appears with the title Expression Editor. You open it from:

  • The expression button beside a property in the Properties panel, and the Expressions tab of that panel.
  • The Expression property of a calculated field. See Calculated fields.
  • The condition of a formatting rule. The editor then has the title Condition Editor.
  • The summary of a control. The editor then has the title Summary Expression Editor.

Parts of the editor​

  • Expression box: You type the expression in it, or build it by clicking items.
  • Item lists: Fields, Variables and the function categories, among them Summary, Reporting and Al-Ameen. Select an item to see its description, then add it to the expression.
  • Operator bar: Buttons that enter operators when you click them.
  • Description: When you select a field the editor shows its type, and when you select a function it shows its syntax and description.

Writing an expression​

ElementFormExample
FieldIts name in square brackets[Quantity]
Report parameterIts name after Parameters. in square brackets[Parameters.CurrencyId]
TextBetween single quotation marks'Bulk'
NumberAs it is0.15
FunctionIts name, then the arguments in parenthesesToPrice([Price])

To insert a field or a report parameter, double-click it in the list of the expression editor; the editor writes the path that the band needs. The examples write a field by its column name in brackets.

The operators:

KindOperators
Arithmetic+, -, * and /
Comparison=, <>, <, >, <= and >=
LogicalAnd, Or and Not

The + operator also joins texts. To choose between two values by a condition, use Iif(condition, value if true, value if false).

Examples with the fields of invoice lines:

PurposeExpression
The value of a line[Price] * [Quantity]
A condition for a large quantity and a low price[Quantity] > 10 And [Price] < 50
A text that changes with the quantityIif([Quantity] > 100, 'Bulk', 'Normal')

Built-in functions​

The editor shows the functions in categories, and the description of a function appears when you select it. Among the standard report functions:

FunctionWhat it returns
Rgb(Red, Green, Blue) and Argb(Alpha, Red, Green, Blue)A text that defines a color from the values of its channels.
CurrentRowIndexInGroup()The index of the current row within its group.
GroupIndex(level)The index of the parent group row at the level you specify.
PrevRowColumnValue(columnName) and NextRowColumnValue(columnName)The value of the column in the previous row or in the next row.
UtcToLocalTime(DateTime) and LocalTimeToUtc(DateTime)Converts a time between UTC and the local time zone.

The editor also has other standard functions, and the description of each appears when you select it.

Aggregate functions on a collection​

These functions calculate over a collection of records with an optional condition. The form:

[Collection][Condition].Sum(Expression)

You can use Avg, Count, Max, Min, Single, Join and Exists in place of Sum. Count returns the number of records that meet the condition, Join concatenates the values into one text with a comma by default, and Exists tells whether the condition holds in the collection.

Summary functions​

The functions of the Summary category calculate over the summary region: the group, the page or the report. Their names start with sum:

FunctionWhat it returns
sumSum(Expression)The total.
sumAvg(Expression)The average.
sumCount(Expression)The number of values.
sumMax(Expression) and sumMin(Expression)The largest value and the smallest value.
sumRunningSum(Expression)The running total: the sum of the values printed before the current row, with its value.
sumPercentage(Expression)The ratio of the value of the current row to the total of the values.
sumRecordNumber(Expression)The current record number within the summary region.

There are also sumMedian, sumWAvg, the standard deviation and the variance, and their counterparts for distinct values (sumDSum, sumDCount and sumDAvg). The argument of a summary function cannot contain another summary function. Summaries and their examples are in Summaries.

Variables​

The Variables list gives you values that the report calculates while it prints:

VariableMeaning
Current row indexThe index of the current row in the data source, starting from zero.
First row and last rowWhether the current row is the first row or the last row in the data source.
Row countThe total number of rows in the data source.
Page index and page countThe index of the current page starting from zero, and the total number of pages.

Choose the variable from the list so that the editor writes it in the right form.

alameen functions​

alameen ERP 10 adds to the editor a category of functions named Al-Ameen. When you select a function from it, the editor shows its syntax and description. It includes:

GroupFunctions
Format numbers by the program optionsToPrice, ToQuantity, ToBalance and ToExchangeRate
Format date and timeToDate, ToDateTime and ToTime
Write in wordsNumberToText(Value, CurrencyId)
Information about the user, the program and the databaseIsAdmin, GetUserName, GetLanguage, GetServerName, GetDatabaseName, GetDatabaseFullName and GetDatabaseDescription
  • The format functions take one value. The number functions accept a numeric value, and the date functions accept a date value.
  • NumberToText writes the amount in words by the currency of the ID you give it: NumberToText([GrandTotal_ic], [Parameters.CurrencyId]) in an invoice template, where GrandTotal_ic is the invoice total in the invoice currency.
  • The other functions take no arguments, and are written with empty parentheses: GetUserName().

The full explanation of each function, and the options it follows, is in alameen functions in expressions.

Checking the result​

After you write the expression, open the Preview tab to see its result with the data of the saved document. If an empty text or an unexpected value appears, check the field name and the position of the control in the band.

This page applies to alameen ERP 10, version 10.1.79.764.