Question
I encountered the following task. There is a JSON of the form:
[
{
"sum": "10.00",
"quant": "1.00",
"id": "196"
},
{
"sum": "5.00",
"quant": "1.00",
"id": "342"
},
{
"sum": "15.00",
"quant": "2.00",
"id": "210"
}
]
This field is inside a loop with the contents of the order.
I want to create an informational field in the loop table in the row of this order with the contents from inside the loop in the form:
Item name 1 - (id 196) - 1 - sum: 10.00, Item name 2 - (id 342) - 1 - sum: 5.00, Item name 3 - (id 210) - 2 - sum: 15.00.
How can I do this?
Answer
To convert JSON into text of the desired format, you can iterate over this rowlist using listReplace, adding another column with concatenated values, and then take this column and turn it into text using listJoin:
Code in the text-type information field in the cycle table:
=: listJoin(list: $replace[[concatenated]]; str: str`"," + $#nl`)
replace: listReplace(list: $data; action: "concatenated" = $concatenated; value: "value")
data: select(table: 'table_in_cycle'; cycle: #id; field: 'f_data')
concatenated: str`$item_name ++ "-" ++ "( id" ++ $#value[id] + ")" ++ "-" ++ $#value[quant] ++ "-" ++ "sum:" ++ $#value[sum]`
item_name: select(table: 'items'; field: 'name'; where: 'id' = $#value[id])