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.
Codes in the table are executed in a specific order:
If
Field 2
refers toField 3
from the code via#name_field_3
, the result will be empty, because in the given exampleField 3
is calculated afterField 2
.
You can move the field display to another placement or another sort.
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 action functions from codes is not available except for:
reCalculate — be careful, it is very easy to create an infinite loop in the table.
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 ...
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!
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 codes are executed after the calculation codes are completed.
The action code of a field is triggered if one of the triggers is activated.
CodeActionOnAdd — execute the action code when adding a row/creating a cycle.
CodeActionOnChange — execute the action code when the field value changes.
CodeActionOnDelete — execute the action code when deleting a row.
CodeActionOnClick — execute the code on double-clicking a locked field.
The order of execution of field action codes in the table is similar to the order of code execution.
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.
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)
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.
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.
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:
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:
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:
linkToPrint — calls the print window:
linkToButtons — calls a panel with buttons.
linkToInput — calls an input window:
linkToAnonymTable — a special function that encrypts parameters for anonymous tables.
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.
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.
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: "")
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 thevar:
parameter.Panel elements will be available even if the role has
read-only
access — set visibility throughcondition
and variables$#nr
and$#nu
.
Rows are formatted using the setRowFormat function, which can block row deletion, duplication, or movement.
Tables are formatted using the setTableFormat function.
The buttons:
parameter allows you to move the specified buttons to the row part.
In the Creator layer, buttons specified in
buttons:
will be displayed in their standard placement.
Any
block
,blockdelete
,blockadd
, ... blocks set in Formatting are weak as they are implemented on the browser side!
Strong server-side blocks are:
Action codes in conjunction with the errorExeption function.
Table action code in conjunction with the errorExeption function. For example:
ch5=: if(condition: #status != json`[1,2]`; then: $err)
err: errorExeption(text: "Cannot change the field if the order is in Paid status")