Question
There is a field #pos with a value of type list [12,215,55]
. When this field is changed, the action code should write this list to another table, combining the ids from this list with the names from the nr_name
field from another table.
As a result, you should get a list ["12 - item_name_1", "215 - item_name_2", "55 - item_name_3"]
I thought of using listreplace to add names to the ids, but I can't figure out how it works:
=: set(table: 'some_table'; field: 'list' = $sel; where: 'id_link' = #id; log: true)
sel: listReplace(list: #pos; action: "item" = $val; action: $val; value: "value")
val: select(table: 'test_projects_'; field: 'nr_name'; where: 'id' = $#value)
Can you tell me what I'm doing wrong?
Answer
Corrected action code for this case:
=: set(table: 'some_table'; field: 'list' = $sel; where: 'id_link' = #id; log: true)
sel: listReplace(list: #pos; action: $val; value: "value")
val: strAdd(str: $#value; str: " - "; str: $name)
name: select(table: 'test_projects_'; field: 'nr_name'; where: 'id' = $#value)
action: "item" = $val; — this action format in listReplace adds a column if a rowlist is received in the list. In your case, it's just a list, so you need to use action: $val;
.
val: strAdd(str: $#value; str: " - "; str: $name) — to obtain concatenated data, concatenation must be performed at each step of executing listReplace.