@Joao_Macau
A couple of things:
Your problem is that ForAll is not a For/Loop. It is a formula that creates tables based on the information provided.
The information you are providing is a Record (from the first If) a Record from the second if, and the Remove will return a Table. So the inner record of your ForAll is mismatched and not valid.
You mentioned two collections, but your formula also uses a "CollectionA". What is the relevance of that?
You need not create multiple collections of the same information as this can all be achieve with 1 or no collections.
Consider RemoveIf instead of the Remove function as your success in matching a record will be much higher.
RemoveIf should reference the primary key of the list to delete from - in your case ID.
Although you can RemoveIf by other criteria, the ID is the most reliable as your list grows in size.
Your ThisRecord references are referencing the wrong values in your current formula. ThisRecord needs to be used with caution as it references the most recent record in the formula chain. So for example in your "change" logic, it is referencing the LookUp values, not the record from the table iteration of the ForAll.
Please consider changing your Formula to the following:
Collect('MaR.OOP';
ForAll(
Filter(ColletionA; Ação="Add") As _item;
{Title: _item.OOP; '0A ID OE': _item.OE; 'AF Valor':_item.Novo}
)
);;
Patch('MaR.OOP',
ForAll(
Filter(ColletionA; Ação="Change") As _item;
{ID: _item.ID;
'AF Valor': _item.Novo}
)
)
);;
ForAll(
Filter(ColletionA; Ação="Remove") As _item;
RemoveIf('MaR.OOP'; ID=_item.ID)
)
Also, you do NOT need the costly Refresh on your list that you had in the formula. The changes you make will be immediately reflected in your app.
The above formula assumes that you have the information you need for your records in the CollectionA collection. For simplicity of your formula, I would strongly consider making sure that collection has the values you want rather than doing another lookup to another collection to get the same values.
IF for some reason that is by design, then let me know and we can alter the above to fit that.
I hope this is helpful for you.