Question
There is a field where I select values through a Select-tree. How can I make it so that after selection, new rows are created in another table, recording each selected value in a new row?
Answer
A field with the type Select-tree or Select with the Multiple parameter enabled stores a list.
First, you need to determine which elements are selected as a result of changing the field. This can be done by the difference of lists, using the listMinus
function.
To determine what:
Added — you need to subtract the previous list of field values from the current one
Removed — you need to subtract the current list of field values from the previous one
Based on this data, add or remove rows from the necessary table:
In the field action code with Select-tree or Select with triggers for addition, modification, and deletion:
a1=: insertList(table: 'some_table'; field: 'some_field' = $listAdd; log: true)
listAdd: listMinus(list: $#nfv; list: $#onfv)
a2=: deleteList(table: 'some_table'; where: 'some_field' = $listDel; log: true)
listDel: listMinus(list: $#onfv; list: $#nfv)