Wednesday, July 28, 2021

Power Automate: CRUD Operations Using REST API - Part 2

Hello Friends,

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

  1. Power Automate: CRUD Operations Using REST API - Part 1
In this post, we will learn Update 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-Create" 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-Update" 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. Again click on 3 dots and click on Edit.
  3. Add another input parameter ItemID by using Compose action.


  4. Now expand the step "Send an HTTP request to SharePoint".
  5. Change the Method from POST to PATCH.
  6. Update the Uri by adding ItemID parameter so that when the update command is executed, the REST API should know, which item to update.
  7. Next, add one more key-value in Headers-
    1. Enter key: IF-MATCH
    2. Enter value: *


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


  12. As you can see the tooltip, you will be getting 3 input parameters-
    1. ComposeTitle_Inputs
    2. ComposePinCode_Inputs
    3. ComposeItemID_Inputs
  13. What are you waiting for? Provide the values for Title, PinCode, ID. Now you will be surprising that values for Title and PinCode will be provided using DataCards but from where, we will get the value of ID? The value of ID will be provided by the gallery placed on BrowseScreen. As you will click on an item in gallery, it will take you to Details screen, from there you will click on Edit icon to edit the item. So, the item you had selected in gallery, will provide us the value of ID.


  14. Thus the complete code is-
  15. 'HTTPCRUD-Update'.Run(
        DataCardValue3.Text,
        DataCardValue4.Text,
        BrowseGallery1.Selected.ID
    );
    Navigate(
        BrowseScreen1,
        None
    );
    
  16. That's all. Save the PowerApps and run to see the magic.


  17. And the SharePoint list with updated data is-


  18. With this, Part 2 of the series is over. We have learned update record using PowerApps, Power Automate and REST API.
  19. So far, we have learnt abut the Insert & Update of record.
  20. In next part, we will learn about deletion of record.

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.