Problem is that within a foreach when you're at item()
level, you're comparing the value with body/value
which is an object. It will certainly 'not contain' the ID you're passing and will always generate a new record.
here an approaches to do this.
Get all IDs in the excel with a select
and then check for the ones that dont exist. then add them.
As you see, the condition is now false. Ensure that the datatype of your ID is string (parse it using string()
function if not) since select
always returns an array of strings.
Better approach
an even better approach to avoid repetitive conditions in the foreach
loop is by using a filter array
to get all items that don't exist and then create them in the loop.
here's a sample structure using filter array
only six out of 20 were added