Hi NaufalWahika,
Thanks for coming back to me so quickly!
I found the route of my issue after a lot of trial and error! Intersection() only gave me results if the fields were strings! I had a mixed data type of integers/numbers, boolean and strings. Took me a while to figure out!
Use case:
I am synchronising 2 lists - Microsoft Todo and a SharePoint list. This is to enables me to use custom fields and reports and also benefit from the integration of MS Todo!
To sync from SP to Todo, I have used an event driven flow... all fine. To sync the other way (Todo to SP), I think the only option I have is to schedule a flow that looks for differences between the data sets and updates the records accordingly.
Solution:
I prepare an array for all the open tasks in SP. I then prepare an array containing all the open tasks (or completed in less than a day) in Todo along with the SharePoint ID to the corresponding SP record using xPath. If this information is missing, I add a new list item to SP. For all "exsiting" records, I use an intersection() to find the common records. I then use a Select function on the Todo List with the addition of xPath (counting common records) to identify which records need updating in SP (records with zero count)! This means I do not need an "Apply to each" (until I get to the Sharepoint… yet to work out batch editing / adding of sharepoint records).
There are a few other bits I need to do in the process and happy to share if you (or anyone else) are interested.
Snippets:
xpath(xml(outputs('Compose_JSON')),concat('number(/root/tasks[TodoID="',item()?['id'],'"]/SPID)'))
intersection(body('Select_T2'),body('Select_T1'))
xpath(xml(outputs('Compose_Matching_Tasks')),concat('count(/root/tasks[TodoID="',item()?['TodoID'],'"])'))
Kind regards,
Priddo