Search code examples
azure-logic-appspower-automate

Power Automate. Delete from parent and child list using ID from parent list


I have a Tasks list in Sharepoint with fields like ID, priority and deadline. I also have a TaskActions list with the people to whom the task has been assigned. The Tasks list is like a parent list. The TaskActions list is like a child list. The ID of the task is a lookup field in the TaskActions list and is called TaskID. I need a Power Automate Flow or logic app that retrieves the ID of tasks which had a deadline more than 6 weeks ago.
It then deletes those tasks from the TaskActions list then the Tasks list. I've used GetItems to retrieve the tasks, but my Flow is failing to retrieve the TaskID possibly because it's a lookup field. I hope this screenshot helps explain things.

enter image description here


Solution

  • Follow the below step by step process to delete the items from the Tasklists list.

    This is the sample data that I took in the Tasklists.

    First use Sharepoint - Get items action to get the items of the given list. In the Filter query, add the filter condition like below.

    concat('<deadline> gt ''',addDays(utcnow(),-42,'yyyy-MM-dd'),'''')
    

    enter image description here

    This will give all the required items. Now, take a for each loop and give this array to it as value.

    Inside For loop use Sharepoint - Get file meta data to get the required Id from the file meta data. Then use that Id to delete that item like below.

    enter image description here

    This will delete the Items in the Tasklists list.

    enter image description here

    To delete the items with same ID in another list, add the below actions in the same for loop after the above actions.

    • First use Get items with the list name. In the Filter query give the below expression.

      concat('ID eq ',items('For_each')?['ID'])
      
    • It will give the required item details as an array. After this, use the same above actions again. First use Get file meta data action and get this item meta data properties. Use the below expression in the File identifier.

      body('Get_Items2')?['value'][0]?['{Identifier}']
      
    • This will give the Item meta data properties. Now, use Delete file action after this and give the below expression in the File identifier.

      body('Get_file_metadata2')?['Id']
      

    In this way it will delete all the files from the other list as well.