⟵ hearthere ⟶
  • Quick start
  • Install MIT
  • Install PRO
  • Updating
  • Optimization
  • Update v4-v6
  • Backups
  • Console utility bin/totum
  • Basics for users
  • Interface and Layout
  • Tables and their parameters
  • Prefilter
  • Fields and their parameters
  • Syntax
  • Code, actions, formatting
  • Code
  • Calculation Sequence
  • Recalculate Rows
  • Executing Actions from Code
  • linkToDataTable in Codes
  • Using old-values
  • Action Code
  • Triggers
  • Execution Sequence
  • Special Syntax
  • Multiple actions with the while function
  • Iterating through a list with the listReplace function
  • Features
  • linkTo functions for window calls
  • Sending emails and calling external scripts from action code
  • Formatting
  • Special syntax
  • Panel functions
  • Row formatting
  • Table formatting
  • Weak and strong blocking
  • Relational relationships
  • Calculation order and calculation units
  • Auto-complete calculations and timing
  • Duplicate rows and cycles
  • Comparisons
  • Functions
  • Debugging
  • Print and CSV
  • API
  • Roles and users
  • Notifications
  • Scheduled Actions
  • System tables
  • Trees
  • Anonymous tables
  • External Forms
  • Exporting and importing tables
  • [PRO] MeiliSearch
  • [PRO] Databases
  • [PRO] Custom CSS
  • [PRO] Custom docs
  • [PRO] LDAP AD
  • [PRO] File versions
  • [PRO] List-unsubscribe
  • [PRO] Dynamic fields
  • [PRO] Only Office
  • [PRO] Auth Tokens
  • [PRO] 2FA
  • [PRO] Superlang
  • [PRO] Daemons
  • [PRO] Profiler
  • Connecting functions
  • [SRV] Installation and Connection
  • [SRV] Export, PDF, Upload, and Preview
  • [SRV] XLSX/DOCX Generators
  • Features of Codes

    Code

    Calculation Sequence

    Code is a formula used to calculate the value of a field. Each time a recalculation unit is triggered, it is executed anew for each field.

    More about Syntax ⟶

    Codes in the table are executed in a specific order:

    Code

    If Field 2 refers to Field 3 from the code via #name_field_3, the result will be empty, because in the given example Field 3 is calculated after Field 2.

    You can move the field display to another placement or another sort.

    Recalculate Rows

    For Calculated tables within a cycle and Temporary tables, this is irrelevant as they are always recalculated upon opening and any change.

    Simple tables and Cycle tables, on the other hand, have a row recalculation unit, i.e., Codes in fields are executed when a change occurs in one of the row's fields.

    To recalculate rows from the interface, you can use Recalculate:

    If the Code has an additional parameter Execute only on addition enabled, a simple Recalculate will not update the data in this field. This can be done by writing an action code with the recalculate function with specified field parameters.

    To simplify this in the PRO version, you can use Recalculate +.

    Executing Actions from Code

    Executing action functions from codes is not available except for:

    reCalculate — be careful, it is very easy to create an infinite loop in the table.

    How to fix a deadly loop ⟶

    It is used to update data in the source table and ensure fresh data is taken:

    example1: while(preaction: $rec; action: $select)
    
    rec: reCalculate(table: 'table_name')
    
    select: select(table: 'table_name'; field: 'field_name'; where: 'id' = #item)
    
    

    getFromScript — use with caution. If the remote server does not respond, the calculation will fail with a runtime error.

    linkToDataTable — for calculation through a hidden temporary table. See the next heading ...

    linkToDataTable in Codes

    • linkToDataTable — in codes, a temporary table can be called without showing it to the user.

    For this, the hide: true parameter must be passed during the call.

    In this case, a hash of the temporary table will be returned, and the final data can be taken from it via select.

    sel: selectRowList(table: 'tmp_table'; hash: $hash; field: 'data'; field: 'summ'; order: 'id' asc)
        ~hash: linkToDataTable(table: 'tmp_table'; params: $row; hide: true)
            row: "here are the parameters passed to tmp_table"
    

    This method generates a load on the database, as temporary tables are recorded and deleted within an hour.

    It is not recommended to use this approach in row parts!

    Using old-values

    In codes, it is also possible to use old. values. For example:

    example2: if(condition: #param = true; then: #old.number; else: #number)
    
    // Example code for a checkbox, switching it to a new value with each recalculation.
    
    example3: if(condition: $#onfv = false; then: true; else: false)
    
    

    Action Code

    Action codes are executed after the calculation codes are completed.

    Triggers

    The action code of a field is triggered if one of the triggers is activated.

    Execution Sequence

    The order of execution of field action codes in the table is similar to the order of code execution.

    Action Code

    Special Syntax

    An action code can be executed from the =: section — this is a simple option if a single action needs to be performed.

    The starting section must initiate an action function! These are functions of the recalculation, insertion, and modification sections, window and script calls, or logic.

    =: reCalculate(table: 'table_name')
    

    Multiple sequential actions can be performed:

    a1=: set(table: 'table_name'; field: 'field_name' = #field)
    
    a2=: reCalculate(table: 'table_name')
    
    • a — applies to any trigger.

    • ch — only on change.

    • ad — only on addition.

    • dl — only on deletion.

    • cl — on double-clicking a locked field.

    The corresponding trigger must be active.

    //execute on addition
    ch1=: set(table: 'table_name'; field: 'field_name' = #field)
    
    //first action on deletion
    dl1=: reCalculate(table: 'table_name')
    
    //second action on deletion
    dl2=: reCalculateCycle(table: 'cycles_table'; cycle: #old.cycle)
    
    

    Execution order by row sorting: digit 12 < 2.

    a are executed first for any trigger.

    Multiple actions with the while function

    You can also perform multiple actions using the while function:


    dl3=:
    while(action: $recalc; action: $cycle) recalc: reCalculate(table: 'table_name') cycle: reCalculateCycle(table: 'cycles_table'; cycle: #old.cycle)

    Iterating through a list with the listReplace function

    listReplace allows you to sequentially perform actions by iterating through a list.

    replace_act: listReplace(list: $list_date_act; action: $recalc_repl; value: "val_act")
        list_date_act: listCreate(item: "2020-09-10"; item: "2020-09-11"; item: "2020-09-12")
        recalc_repl: recalculate(table: $#ntn; where: 'date' = $#val_act)
    
    // The action code will sequentially recalculate the rows of the current table where the date equals the dates from list_date_act.
    
    

    Features

    • When adding, old value is equal to null.

    • When deleting, the current value is equal to null. If you need the deleted value, refer to it through #old.fieldname.

    • Data is saved to the table after all actions are completed, so select functions from the current row may fetch outdated data — use #.

    • If as a result of an action you change a value that a subsequent action refers to, fetch it through select. This is because # values are taken at the moment of the first action execution.

    linkTo functions for window calls

    Functions that call windows are grouped under linkTo...:

    • linkToTable — opens a table in a blank, self window or iframe with enabled or disabled non-row placements and with parameter passing in the prefilter:

      LinkTo

    • linkToScript — calls an external script or web page, displaying it on a new page or in a window.

    • linkToDataTable — calls a temporary table with parameter passing. Can be used for complex modal windows:

      DataTable

    • linkToDataText — opens a window with plain text.

    • linkToDataHtml — opens a window with html. If you want to display an html form — use linkToInput.

    • linkToPanel — opens a table row as a panel:

      Panel

    • linkToPrint — calls the print window:

      Print

    • linkToButtons — calls a panel with buttons.

    • linkToInput — calls an input window:

      Input

    • linkToAnonymTable — a special function that encrypts parameters for anonymous tables.

    Sending emails and calling external scripts from action code

    If you need to send an email as a result of action code execution — emailSend or notificationSend.

    If you need to call an external script with parameter passing — getFromScript.

    If you want to call an internal script on the server — execSSH.

    Formatting

    Conditional formatting code sections:

    Fields — highest priority. Expects the return result of the setFormat function.

    Rows — medium priority. Expects the return result of the setRowFormat function.

    Tables — lowest priority. Expects the return result of the setTableFormat function.

    Special syntax

    The return result should come from a numbered section f1=:, f2=:, ...

    Execution order is by line sorting 12 < 2.

    f1=: setFormat(condition: #type != 1; block: true; text: "—")
    f2=: setFormat(condition: #type = 1; condition: $calc > $#nfv; background: "orange"; color: "white")
    
            calc: #price * 0.1 + #price
    
    f3=: setFormat(condition: #type = 1; condition: #price > $#nfv; background: "tomato"; color: "white")
    
    // When conditions are met, f3 will override f2
    

    A row with higher priority will override the specified parameters!

    Returning to the default value is done by specifying an empty value —> color: "";.

    If you want to combine several actions, for example, display the field value without spaces and in uppercase, then:

    f4=: setFormat(text: $upper)
        upper: strTransform(str: $repl; to: "upper")
            repl: strReplace(str: $#nfv; from: " "; to: "")
    

    Panel functions

    Additional panel

    In addition to f, the prefix p can be used, which will be executed when the panel is opened by right-clicking on the field. Numbering is similar to f.

    p0=: panelHtml(html: $strpanel)
        strpanel: strAdd(str: "Physically in Stock <b>"; str: $flat; str: "</b> of which "; str: $block; str: " are reserved.")
            flat: select(table: 'goods'; field: 'count'; where: 'id' = #name)
            block: select(table: 'goods'; field: 'block'; where: 'id' = #name)
    
    p1=: panelButtons(condition: $block != 0; button: $b1; refresh: true)
        b1: rowCreate(field: "text" = "VIEW RESERVES"; field: "code" = "show_block")
    
    p2=: panelButtons(button: $b2; refresh: true)
        b2: rowCreate(field: "text" = "VIEW MOVEMENT"; field: "code" = "show_move")
    
    

    It must return the result of a function with the panel... prefix:

    • panelButtons — places additional buttons on the panel (one or more).

    • panelButton — places an additional button on the panel (one).

    • panelImg — places an image on the panel.

    • panelHtml — displays html on the panel.

    Panel functions receive the environment of the table and row from which they were called — #id, $#nci, $#ntn, $#nti. Additional variables can be passed through the var: parameter.

    Panel elements will be available even if the role has read-only access — set visibility through condition and variables $#nr and $#nu.

    Row formatting

    Rows are formatted using the setRowFormat function, which can block row deletion, duplication, or movement.

    Table formatting

    Tables are formatted using the setTableFormat function.

    Table formatting

    The buttons: parameter allows you to move the specified buttons to the row part.

    Buttons

    In the Creator layer, buttons specified in buttons: will be displayed in their standard placement.

    Weak and strong blocking

    Any block, blockdelete, blockadd, ... blocks set in Formatting are weak as they are implemented on the browser side!

    Strong server-side blocks are:

    ch5=: if(condition: #status != json`[1,2]`; then: $err)
    
    err: errorExeption(text: "Cannot change the field if the order is in Paid status")