Wednesday, July 28, 2021

Power Automate: CRUD Operations Using REST API - Part 3

Hello Friends,

Welcome back with another post on Power Automate. In last 2 posts, we were discussing about CRUD operations using REST API in Power Automate with PowerApps. There, we had learnt about Insert and Update the data in SharePoint. You may visit my these posts by clicking on below link-

  1. Power Automate: CRUD Operations Using REST API - Part 1
  2. Power Automate: CRUD Operations Using REST API - Part 2
In this post, we will learn Delete the data. For this, we have to do nothing very much. Let's start without any wait-
  1. Open the Power Automate portal and make a copy of the Power Automate flow, we had created in last post by clicking on "My flows". Then click on 3 dots showing ahead of flow "HTTPCRUD-Update" and choose "Save As". It will ask you to provide the name of flow you want to make as a copy. give the name "HTTPCRUD-Delete" and click on Save.


  2. It will create a copy of the flow and by default retain it in Turn off mode. Click on 3 dots ahead of this flow and choose Turn on.


  3. Again click on 3 dots and click on Edit.
  4. As we have to delete the record, that means, we only need the ItemID of that record. So we can delete the Compose actions written for Title and PinCode. After deleting, we will have only one input parameter "ComposeItemID_Inputs"


  5. Now expand the step "Send an HTTP request to SharePoint".
  6. Change the Method from PATCH to DELETE.
  7. Add below key-value pair in Headers section-
    1. Enter key: X-HTTP-Method
    2. Enter value: DELETE
  8. Delete the contents of Body section as we have not to update anything; we are deleting the item.


  9. That's all in Power Automate. Click on Save button to Save the flow.
  10. Now come back to PowerApps. Open the PowerApps, we have updated in last post and click on EditScreen1.
  11. Add one more button just next to Update and rename it's text as "Delete" and rename this button as btnDelete.
  12. Now click on the formula box of OnSelect property for this btnDelete and remove the existing code. Then click on Action >> Power Automate and choose "HTTPCRUD-Delete".


  13. As you can see the tooltip, you will be getting only 1 input parameter-
    1. ComposeItemID_Inputs
  14. Provide the value of ID for the item you want to delete and complete the formula.


  15. the complete code will be-
  16. 'HTTPCRUD-Delete'.Run(BrowseGallery1.Selected.ID);
    Navigate(
        BrowseScreen1,
        None
    );
    
  17. That's all. Save the PowerApps and run to see the magic.
  18. For the easiness and clarity, I had added one more record in list. Let's try to delete it.


  19. And the SharePoint list after deleting the data is-


  20. With this, Part 3 of the series is over. We have learned delete record using PowerApps, Power Automate and REST API.
  21. One line, I would like to add here is, I had added custom buttons to perform the actions. The same code can be written on the icons provided for Add/Update/Delete the item in PowerApps.
  22. So far, we have learnt abut the Insert, Update & Delete the record.
  23. The next two parts of this series are quite important as in that posts we will learn on how to get the data using Power Automate, REST API and PowerApps.
  24. Stay tuned...
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.