What is a temporary table?
Temporary table — a special type of table that is created when a user opens it and exists for a limited time (by default, 1 hour). After that, they are deleted from the database.
So if several users open the same temporary table, they will see different tables. The structure will be the same, but the data content will be different.
Why are they used?
For example, for reports or as intermediate technical tables.
Is it possible to open a temporary table from the tree?
By default, the temporary table is available from the tree, but if it is created as a technical one, it will most likely need to be hidden from the tree by setting the parameter roles "hide in tree".
What function is used to open the temporary table?
To open a temporary table, like a regular table from the tree, you can use linkToTable with which we are already familiar.
A feature of the temporary table is that it does not have a prefilter. Therefore, the filter
parameters will not be applied.
But if we want to open a temporary table and fill it with specific data, we need the function linkToDataTable.
What function is used to open a temporary table and send data to it?
If we want to open a temporary table and fill it with specific data, we need the function linkToDataTable.
It has two parameters that distinguish it from linkToTable — data: $rowList
and params: $row
.
data
— data to fill the row part.
params
— data to fill the header and footer.
How it looks. For example, we have a table with the fields client
and order
in the header, and we want to immediately insert the value of the client we need when opening, which we determine from the row from which the opening button is executed:
=: linkToDataTable(table: 'tmp_test'; title: "Temporary Calculation Window"; width: 800; height: "80vh"; params: $row)
row: rowCreate(field: "client" = #client; field: "order" = #order_num)
So in params
you need to pass a row
consisting of the name
fields that need to be filled and their values.
Note that in rowCreate
and similar functions that create a structure with values, the name
parameters of the functions are filled in with double quotes. This rule is not mandatory for correct operation — it relates to code formatting rules.
Is it possible to fill in the rows part, not just the header or footer?
If we want to fill the row part when opening a temporary table, we need to pass rowList
to data
, where each row will be a row in the temporary table.
=: linkToDataTable(table: 'tmp_test'; title: "Temporary Calculation Window"; width: 800; height: "80vh"; params: $row; data: $rowlist)
row: rowCreate(field: "client" = #client; field: "order" = #order_num)
rowlist:rowListCreate(field: "goods" = $list[[goods]]; field: "price" = $list[[price]])
~list: selectRowList(table: 'order'; cycle: #order_num; field: 'goods'; field: 'price')
In this code, we are slightly ahead by referring to the cycle table using cycle
and taking rowList
from which we use the goods
column in goods
and the price
column in price
using [[column]]
.
More about nested references here, but we will discuss them further.
Is it possible to pass only part of the data and calculate the rest in the table?
Quite often, data is transferred line by line into a hidden leading technical field in the row part, and then distributed across the fields:
=: linkToDataTable(table: 'tmp_test'; title: "Temporary Calculation Window"; width: 800; height: "80vh"; params: $row; data: $rowlist)
row: rowCreate(field: "client" = #client; field: "order" = #order_num)
rowlist: rowListCreate(field: "teh" = $list)
list: selectRowList(table: 'order'; cycle: #order_num; field: 'goods'; field: 'price')
And then in the goods
field, the following code is used:
=: #teh[goods]