⟵ hearthere ⟶
  • Training course
  • Creating simple tables and fields
  • Codes base level
  • Selects and links between tables
  • Table settings basic level
  • Prefilters base level
  • Conditional formatting basic level
  • Action codes base level
  • Set a new value to another field when the current field is changed
  • Performing several actions in sequence
  • Executing code from the button, logging
  • Add or delete rows in a table
  • How to recalculate rows in a table
  • How do I set different values depending on the values in the column?
  • Using pop-up windows
  • Cycles base level
  • Roles and users on the web
  • Codes advanced level
  • Action codes advanced level
  • Prefilters advanced level
  • Field and table settings advanced level
  • Cycles advanced level
  • Formatting advanced level
  • Select-Tree
  • Executing a scheduled action code
  • Printing and emailing
  • Notifications
  • API interaction
  • Adaptivity and Sections
  • Performing several actions in sequence

    code_action

    Can an action code have multiple = sections?

    Yes. Action codes can look like this:

    a1=: set(table: 'table'; field: 'fild_name' = #new_value)
    
    a2=: recalculate(table: 'summary')
    
    

    Prefixes a indicate an action triggered by any event — addition, deletion, modification, or double-click.

    The execution order will follow the numerical order processed as a string.

    Thus, a11 will be executed before a2.

    What prefix should I use to execute an action code only on a certain trigger?

    • a — general (it will be executed before all others).

    • ch — change only.

    • ad — addition only.

    • dl — deletion only.

    • cl — on double-click on a locked field.

    Thus, in one field, you can set different actions for different triggers:

    a1=: pin(table: $#ntn; field: 'name'; where: 'id' = #id)
    
    ad1=: set(table: 'table_1'; field: 'set_field' = $#nfv; where: 'link' = #id)
    
    dl1=: set(table: 'table_1'; field: 'set_field' = ""; where: 'link' = #old.id)
    
    a2=: recalculate(table: 'summary')
    
    // More about previous values #old.** will be discussed later
    
    

    In this code:

    • The a section, consisting of two actions a1 and a2, will always be executed (at least one trigger must be enabled).

    • ad1 only on the addition trigger (the trigger must be enabled).

    • dl1 only on the deletion trigger (the trigger must be enabled).

    What two ways are available to perform multiple actions in sequence?

    1. Use multiple =: sections with prefixes.

    2. Use the while function. Example:


    =:
    while(action: $action1; action: $action2) action1: set(table: 'table'; field: 'set_field' + #new_value) action2: recalculate(table: 'summary') // About relative change using set — field: 'set_field' + #new_value, will be explained a bit later

    If you use only the action parameters in while, they will be executed sequentially once.

    Can I add conditions to check if an action needs to be performed?

    Yes, you can use if, for example:

    =: if(condition: $#nfv != ""; then: $action)
    
        action: insert(table: 'table'; field: 'field' = $#nd)
    
        // the else parameter can be omitted
    
        // insert adds rows
    
    

    In this example, if the current field is not empty upon change, a row will be added to the table, and the field in it will be set to the current date.

    Or through condition in while:

    =: while(condition: $#nfv != ""; action: $action)
    
        action: insert(table: 'table'; field: 'field' = $#nd)
    
        // action will be executed only if all conditions evaluate to true