Hello Friends,
Welcome back with another post on Power Automate. In last 3 posts, we were discussing about CRUD operations using REST API in Power Automate with PowerApps. There, we had learnt about Insert, Update and Delete the data in SharePoint. You may visit my these posts by clicking on below link-
- Power Automate: CRUD Operations Using REST API - Part 1
- Power Automate: CRUD Operations Using REST API - Part 2
- Power Automate: CRUD Operations Using REST API - Part 3
- 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-Delete" 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-Read" and click on Save.
- 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.
- As we have to read the records from SharePoint list and send them to PowerApps, hence, we need no input parameter for Power Automate. We will directly choose "Send an HTTP request to SharePoint" step.
- Therefore, remove all the input parameters appearing in Power Automate.
- Now expand the step "Send an HTTP request to SharePoint".
- Change the Method from DELETE to GET.
- Remove all key-value pairs from Headers.
- Replace the Uri with "_api/web/lists/getbytitle('ListForRESTAPI')/items". As we have to get the data hence no need to pass any item id.
- Now, the Power Automate will look like-
- Now add "Initialize variable" step and give the Name as "strIntermediateOutputString". This variable will be used to hold the delimiter based values that we have to send back to PowerApps.
- Now the process is that we have to -
- First combine the values of each column of an item using a delimiter (call it as Value Delimiter). Let's take "~" (tild) sign as value delimiter.
- Then combine each string of above step with another delimiter (Item Delimiter). Let's take "|" (pipe) sign as item delimiter.
- For example Sachin Jain~110045|Ramesh Gupta~201001. Here Sachin Jain~110045 and Ramesh Gupta~201001 are two separate items in list and there are separated with each other by pipe (|) sign. While in each item the values of Title column and PinCode column are separated by tild (~) sign. So, we have to create this type of string from the output of "Send an HTTP request to SharePoint" step. For this, we will use "Apply to each" step.
- Click on + New step and choose "Apply to each" action.
- Click in the box provided to "Select an output from previous step" and in the popup just opened, paste below expression in Expression box "outputs('Send_an_HTTP_request_to_SharePoint')?['body']?['d']?['results']".
- Here we are asking to Power Automate to get the results available in body.d.results as input. The "Send_an_HTTP_request_to_SharePoint" is the name of HTTP action you had used above. In case of any name change, change here also (also replace blank spaces by underscore)
- As we have to recursively append the string hence now we will add "Append to string variable" action. It will append the data as per our desire (we have shown in sample above). Now select the string variable (we have declared above) in Name dropdown.
- The value section will contain a formula which will concatenate the Title and PinCode values delimited by "~" sign and then concatenate the "|" sign at the end of each loop.
- But before that just type any static value in "Value" box and save the flow. Then close the flow and reopen it.
- The reason behind doing this activity is that without saving and closing the "Apply to each" action didn't reflected in Dynamic content section. Once you reopen it, you will find that the display of "previous output" box appearing now in different mode.
- And when you click on "Value" box of "Append to string variable" action, you will find that in Dynamic content window, "Apply to each" starts appearing.
- The formula will be-
- concat(items('Apply_to_each')['Title'],'~',items('Apply_to_each')['PinCode'],'|')
- This way, we had concatenated all the information required to send back to PowerApps. Now we will remove the last pipe sign as it is unwanted (otherwise it will create a problem while converting the data to collection in PowerApps).
- Use the Compose action with substring and sub (subtract) expression to remove the last character.
- The formula is-
- substring(0,sub(length(variables('strIntermediateOutputString')),1))
- Now, we have to send this data back to PowerApps. For this, click on "+ New step" and add action "Respond to a PowerApp or flow".
- It will ask you to add an output. Click on that link "+ Add an output". It gives 6 types of output-
- Text
- Yes/No
- File
- Number
- Date
- As you can see, there is no option to send the dataset/object, we have created the string of data.
- Now, choose Text option. It will ask you to provide the title and the value you need to send back.
- Let's give the Title as "ResultSet" and in value field, choose the Outputs of Compose action just defined above.
- This way, we have completed the design part of Power Automate. now click on Save to save the changes.
- You may take a test of this Power Automate by clicking on Test >> Manually >> Test >> Run Flow >> Done.
- The output of Compose action which is sent to PowerApps comes out to be as-
- This is the output we need to send back to PowerApps. Here we know that the first part of item is Title and second part is PinCode.
- With this, Part 4 of the series is over. We have learned to get the data from SharePoint using REST API in Power Automate and then did some work around to convert it into string and sent back to PowerApps.
- The next (last) part of this series is the final post of this series where we will implement our logic to convert the string received from Power Automate into collection.
- 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.