A couple of days ago, I was helping a friend with a case in Microsoft Flow … So I thought this is a good time to write a new article that would be a reference for my friend, and hopefully others would find this useful if they came across the same issue.
It’s very simple and straight forward, we have a flow that gets initiated once an item is added to a SharePoint list, and we want to return a JSON object of the newly added item … Easy!
Good to know…
Now before going into the solution, it’s good to know that Microsoft Flow itself handles data within as JSON, whereas Flow is not only a process automation service, it’s an integration service as well. Therefore it needs a common ground/language/format – you name it – to handle all data types from all the different sources (SharePoint list, SQL Table, Excel, etc…)
This is How…
Well, there are two different ways to tackle the case above, and I’m going to list them both in this article.
For the sake of easy illustration in this article, I have created a custom list in SharePoint called “Creative Ideas” and it has two columns (Title and Description)…
If you are familiar with Flow, you’ll know that when an action or a trigger is created there are a set of various properties (Dynamic content) that are associated with each Flow building block, and in our case the newly added item properties are returned along with the trigger. So we can use them to build our JSON.
As we can see from the figure above, we’ve added an “Initialize variable” action right after the trigger, and we have built the JSON object manually in the initial value field. The output value of the variable should look something like this:
The following solution is as clean and neat as the first one, however it involves another call to the SharePoint list which could be an overhead in some cases.
When the item is created
From the figure above, notice that we have added the “Get items” action after the trigger, and then we are filtering the action by ID to return only the correspondent item with the trigger (the added item). At this point, notice that we could have returned the “value” property available from the “Get items” action (which is JSON), however we want the JSON to look as clean and neat as solution 1.
In the last action, we have added the “Select” action from the data operations action group, and then provided the “value” property as the field input form “From” (which is expecting a JSON object) and then we have mapped the properties we want to appear in the newly created JSON object (current action). The JSON output would look exactly as the one from solution 1.
Note: Title and description are from the “Get items” action, NOT from the trigger properties. This way the flow would work whether we are returning one item or multiple items.
I hope this helps! Enjoy…
About the Author:
Simply I love what SharePoint is all about, and I’m really passionate about technology, especially the very technical details of my job, I love what I do “being technical”, and I believe that being so passionate about my specialty is what drives me through every day in my career.
Join the ESPC mailing list to receive the best, free content from across the SharePoint, Office 365 & Azure community, including our monthly newsletter and the latest conference announcements. You can unsubscribe at any time with one click.