I have a data model where the root object is a nested structure. Like this:
{
“root”:{
“id” : “1”,
“array1”:[
{ “id”: “a”},
{ “id”: “b”},
{ “id”: “c”}
]
}
}
I have a list bound to the data.array1 as repeat. It’s showing list like:
a
b
c
Now I want to delete a row. I tried as below:
REMOVE_ITEM_BY_KEY(data.root.array1, “id”, current.id)
The issue I am facing is I am trying to use the above formula in SET Data variable step which is expecting an Object. However the REMOVE_ITEM_BY_KEY is returning an Array type.
Can you please guide how I can assign the modified array to the nested structure? Like this:
data.root.aray1 = REMOVE_ITEM_BY_KEY(data.root.array1, “id”, current.id)
To use REMOVE_ITEM_BY_KEY, I believe it will only work with keys at the root level. The way I’ve approached this in my work is to dig into the array, modify the element I want, and then reset the top-level element to the new value.
This worked in testing for me: SET_KEY(appVars.data.root, "array1", WITHOUT_ITEM(appVars.data.root.array1, appVars.data.root.array1[0]))
Essentially it drills into array1, uses WITHOUT_ITEM (a list function) to remove the item you don’t want from the list, and then sets that new list to the value of array1 using SET_KEY (an object function.)
You’ll have to figure out how to swap out the [0] index with your current vars, but hopefully that’s not too complicated.