I have built a flow that gets individuals (in an Excel table) and adds them to a SharePoint List. Before adding the individuals to the list, I want to delete any person that is already in the list to prevent any duplicates and prevent the list from getting too large. However, my apply to each and condition to check if the individual is already present in the list doesn't work.
This is the section of my flow.
Below are the items/code pieces (whatever they are called?) - from top-left to bottom-right.
Apply to each: outputs('Get_items')?['body/value']
Condition left: outputs('List_Import_Rows')?['body/value']
Condition right: items('Apply_to_each_-_Delete_Current_Rows')?['field_STUDENT_NUMBER']
Delete item ID: items('Apply_to_each_-_Delete_Current_Rows')?['ID']
Compose - All values (same as condition left): outputs('List_Import_Rows')?['body/value']
Compose - student numbers (same as condition right): items('Apply_to_each_-_Delete_Current_Rows')?['field_STUDENT_NUMBER']
The result is always false. The outputs are:
The Compose - All Values show the condition left - which is everything in the Excel table.
The Compose - Student Number goes through each student number of every individual in the SP List.
When I seach the student number (for example, 339542) in the All Values output, I do find the value. Therefore, "All values" does contain "student number" - the condition that is being checked. Why does this always show 'false', though?
Any help would be greatly appreciated.
Edit: If there is an easier way to delete all the content in a SharePoint List, I am open to the idea.
Hello @J_Taylor ,
to answer your Edit question - @Paulie78 has a nice article on deleting efficiently all items from a SharePoint list: Power Automate Flow to batch delete SharePoint List Items (tachytelic.net)
Thanks, @tom_riha.
I have been looking at this and it is very useful.
I have been trying to get the delete functioning first, then I will add the rest. However, I am struggling to get it (just the delete section as shown) to work.
Initially, I was getting 404 errors on 'Get Items' and 'Send an HTTP request...'. I 'fixed' this but manually entering the site address and list. The error output for 'Get Items' was "The response is not in a JSON format." and 'Send an HTTP request...' was "clientRequestId: 64128a6b-9397-4d5d-9774-59313ce181a6 serviceRequestId: 47c261a0-a099-1000-8f55-5c27eed6660c".
Now (with adding the manual locations), the flow is succeeding, but I am getting errors returned:
HTTP/1.1 400 Bad Request
CONTENT-TYPE: application/json;odata=verbose;charset=utf-8
{"error":{"code":"-1, Microsoft.SharePoint.Client.InvalidClientQueryException","message":{"lang":"en-US","value":"Invalid request."}}}
--batchresponse_edef5a4f-190b-460f-84a4-2ae9ad1d931d
Content-Type: application/http
Content-Transfer-Encoding: binary
I don't know if @Paulie78 is available to weigh in?
Edit:
The URL that is created from the 'settings' seems to be correct. When I copy and paste it (for example, https://company.sharepoint.com/sites/Behaviour/Lists/Students/ ) the SP list loads well - but I was still getting the 404 errors. (Note, I did have a '/' at the end of 'siteAddress'.)
If the URL above was wrong, maybe that is the reason for the incorrect HTTP request - https://company.sharepoint.com/sites/Behaviour/Lists/Students/_api/web/lists/getByTitle('Students')/items(|ID|) HTTP/1.1.