⟵ 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
  • How to recalculate rows in a table

    code_action

    Why do I need to recalculate rows?

    To update the data in them. For example:

    You have two tables linked to a third one — the starting table. All of these are simple tables.

    They are linked by specifying in the key field of the slave tables the id of the row from the master table.

    These slave tables take some data by codes from the starting table.

    If we change something in the master table — the data in the rows of the slave tables will not update until we recalculate them:

    a1=: recalculate(table: 'slave_1'; where: 'key' = #id)
    
    a2=: recalculate(table: 'slave_2'; where: 'key' = #id)
    

    Why when you recalculate the data in the calculated table, it will be recalculated all of it, independent of where?

    It is always calculated in full, so the calculation tables can be recalculated as follows:


    =:
    recalculate(table: 'table')

    How do I recalculate just the header of a simple table?

    Similarly to the calculation table, without specifying where:


    =:
    recalculate(table: 'table')

    How to recalculate all rows in a simple table?

    All rows where id is not equal to 0:


    =:
    recalculate(table: 'table'; where: 'id' != 0)

    How to recalculate rows and re-execute fields with codes only when adding?

    If the codes are marked execute only on add, they will not re-execute during recalculation.

    For example, this is necessary if you add a product to an order and take its price from the price list using code, and this price should remain unchanged in this order forever.

    But sometimes it is required to make such codes execute again.

    In this case, the field parameter of the recalculate function is used — it indicates that the code in the field should be executed during this recalculation, even if it is only on add.

    =: recalculate(table: 'table'; where: 'id' = $#nfv; field: 'code_only_on_add_field_1'; field: 'code_only_on_add_field_1')
    

    Why does the function recalculate work from the code?

    Yes, the recalculate function works from the code, despite being an action function. This is done so that in very rare cases, the source table can be recalculated before extracting data from it:

    =: while(action: $rec; action: $select)
    
    rec: recalculate(table: 'table'; where: 'id' = $#nfv)
    
    select: select(table: 'table'; field: 'field'; where: 'id' = $#nfv)
    
    

    while also works in the code and returns the last action or postaction as its value.