Formulas and scripts

Formulas

Formulas are used in the program for the following purposes:

  • To display variable data in label elements. Variable data is data from fields in your data source, data from calculated data fields, counters, current date.
    The string returned by the formula will be displayed by the label element when the label is printed or previewed.
    Also, a formula in a label element that displays an image can return the path to an image file or a link to an image.

  • To set various conditions. For example, to set visibility conditions for label elements/layers or to filter your data by certain conditions when importing data from your source.

  • As a data source for calculated data fields. A calculated data field is a data field that is configured with a formula. Such a data field will contain what this formula will return. For example, you can add a data field to the label printing data and set a formula in the settings of this field, according to which this field will display modified data from another data field.

In formulas, you can use string, number, and date/time operations, as well as number and date/time formatting. Various functions are used for this.

To insert and edit formulas in the program, there is a formula designer, which is described in the Formula Designer section.

Formulas look like:

[Initial value] [Function 1] [Function 2] ... [Function N] [/*Your comment*/]

The initial value can be any valid data type. It may be absent explicitly, then it will be considered an empty string.

Types of data in formulas

  • Text. Is enclosed in double quotes.

    Example: "This is a text"

  • Number.

    Example: 123.4

  • Date / Time. Is enclosed in single quotes.

    Format:

    • YYYY-MM-DDThh:mm:ss
    • YYYY-MM-DD hh:mm:ss
    • YYYY-MM-DD

    , where YYYY - year 4 digits, MM - month 2 digits, DD - day 2 digits, hh - hour 2 digits, mm - minutes 2 digits, ss - seconds 2 digits.

    Examples: '2020-09-12T03:41:00', '2020-09-12 03:41:00', '2020-09-12'.

  • Data field. Is enclosed in square brackets.

    Examples:

    • [Price]
    • [CurrentDate], here the virtual data field, which contains the current date.

Functions in formulas

Functions perform various actions: arithmetic operations, processing of strings and dates, formatting, etc.

Functions in a formula are executed sequentially from left to right.
The initial value of the formula acts as an input value for the first function, for all subsequent functions the input value is the result of processing from the previous function. Those. the first function in the formula processes the initial value of the formula, the second value received from the first, the third value received from the second, and so on.

Functions can include other formulas as arguments.

Examples of using functions:

  • String()

    The function converts the input value to a string.

  • +(10)

    The function adds the number 10 to the input value.

  • If(>10;1;0)

    The function returns 1 if the input value is greater than 10, otherwise it returns 0.

  • Round( If( [Price]>10;"1";"0.5" ) )

    The function rounds the input value to 1 if Price data field contains a value greater than 10, otherwise it rounds the input value to 0.5.
    The formula If( [Price]>10;"1";"0.5" ) is used as a function argument that determines the rounding accuracy.

Examples of formulas with functions:

  • 100 AddPercent( 5 )

    The AddPercent() function will add 5 percent to 100 and return the resulting value 105.

  • [Price] AddPercent( 12.3 ) Round( "0.5" )

    AddPercent() function will add 12.3 percent to the price of the item in the Price data field, then Round() function will round the resulting value to a precision of 0.5.

  • If([Name] Contains("pro") Or ([Name] Contains("corporate"));"It is Pro or Corporate";"Other")

    In this example, the functions If, Contains and Or are used.
    The formula checks if Name field contains the words pro or corporate, then returns the string It is Pro or Corporate, otherwise returns the string Other.

JavaScript and Pascal scripts

JavaScript and Pascal scripts are used in the program for the following purposes:

  • To display variable data in label elements.

  • As a data source for label printing.

  • As scripts to be executed when tasks are started.

Script examples:

Both scripts check if the Name field contains the words pro or corporate, then the string It is Pro or Corporate is returned, otherwise the string Other is returned.

  • JavaScript.

    let _ = azureLabel;
    let name = _.getFieldValue('Name');
    if (name.includes('Pro') || name.includes('Corporate')) {
        _.write('It is Pro or Corporate');
    }
    else {
        _.write('Other');
    }

  • Pascal script.

    var name: string;
    begin
        name := GetFieldValue('Name');
        if ( (pos('Pro', name) > 0) or (pos('Corporate', name) > 0) ) then
        begin
            Write('It is Pro or Corporate');
        end
        else
        begin
            Write('Other');
        end;
    end.