What is Microsoft Flow?
Microsoft Flow is an online workflow service that automates events (known as workflows) across the most common apps and services.
With no code involve you can create a complete workflow that will save you time and efforts, lets, for example, assume that you have a daily task of checking all your emails and prioritize them based on their urgency as a task on your favorite To-Do app, you can do that and a lot more using Microsoft Flow.
My Flow
In this blog post, I’ll walk you through the steps needed for creating a specific flow that I found useful, and I needed to accomplish for a particular goal. I needed to post a daily tip on a CMS Platform I work on, Sitecore. But instead of going every day to my twitter account and think of a tip to post and share with the community, I need to have those tips in some place and schedule a tweet every day or so.
Writing the tweets in advance
The first step is to have the source of the tweets ready, I created a new google sheet on my google drive account and started writing the tweets in the following structure.
- No is just a sequential number of the tweet.
- The tweet column will hold the text of the tweet.
- The status will start as New and then will switch to Posted when Flow post the tweet
Create the Flow
Now that we have the sheet ready with all our tweets, it’s time to create the Flow. Go to https://flow.microsoft.com/en-us/, Create a new account or log in if you already have an account.
Microsoft Flow allows you to create flow from the many templates available to automate lots of stuff, but for this one, we will build one from scratch.
- On the left-hand side menu, click on My Flows
- Click on New -> Create from blank
- Click on Create from blank button
In this page, you can search for connectors and triggers that will help you create the flow you want. Since I want to post a tweet every day, first, I’ll need a Schedule service.
- In the search bar, type schedule.
- Click on Schedule icon in the search results.
- In Triggers tab click on Recurrence
- This would be the first step of the Flow, choose the interval and frequency you need this flow to run.
- Click on New Step, this time we need to read from google sheet.
- In the search bar type google sheets.
- Click on Google Sheets icon in the search results.
- In the Actions tab click on Get Row action.
- Because this is the first time you use this connector, it will require you to log in and authorize the app.
- For this connector, you need to pick a file, sheet and enter a row id.
But what is the Row id you need here? Once a connection is made to your google sheet a new column has been added to the sheet called __PowerAppsId__. This is the id you need to reference so before you go to the next step fill in this column with a unique identifier for each row. Insert the first Id you have in the sheet for now. Next, we need to post a tweet we got from “Get row” action.
- Click on ‘New step.’
- In the search bar type Twitter.
- Click on the Twitter icon in the search results.
- Log in to your Twitter account and authenticate the app.
- In the Actions tab click on Post a tweet.
- Click the Tweet Text field, from the pop up choose the Tweet column from the Dynamic Content tab, this tab will contain all data you can get from previous steps.
- Click on New step.
- In the search bar type Google Sheets.
- Click on Google Sheets icon the search results.
- In the Actions tab click on Update row.
- Like we did with “Get Row” step you’ll need to pick a file, sheet and enter a row id.
- Enter the same Id you used in “Get Row” step for now.
- Once you chose the sheet, the fields will appear so you can update them.
- Type ‘Posted’ in the Status field and leave the rest blank.
The flow we wrote so far will read a tweet from the sheet, post it and update the status of this tweet in the sheet. But we have a problem to fix here, every time the flow will run will choose the same tweet. I need to have a dynamic value in the Row id field of the sheet. I couldn’t find a dynamic action that for example can get the first row with ‘New’ status. So instead I added a new sheet in the google document named it Index, added one column only named ‘Index’ as well, the idea is to keep a record of the last id the flow used and not to have static value like 1 in the flow steps.
- Go up to the first step and insert a new step after it by clicking the (+) button
Repeat what you did earlier with “Get Row” step but this time choose Index sheet.
- Again you will need an id here so type 1 in the __PowerAppsId__ in the Index sheet
- Now go to the third step and replace 1 in Row id field with ‘Index’ from the Dynamic Content tab
The last step we need to do here is to update Index so we make sure everytime the flow runs it will read a new tweet so we will create that step at the end of the steps chain.
- Click on New step.
- In the search bar type Google Sheets.
- Click on Google Sheets icon the search results.
- In the Actions tab click on Update row.
- Pick the same file, choose Index sheet and enter 1 in the row id field.
- Once you chose the sheet, the Index field will appear so you can update it.
- This time chose Expressions tab and type the below formula, this will just increase the value of index by 1.
add(int(body('Get_row_2')?['Index']), 1)
That’s it, all that you have to do now is to put the flow in action and test it.
- Save the flow
- Click on Test in the top right corner.
- Choose “I’ll perform the trigger action” option.
- Click on the Test button.
You will see the flow in action, and if any step fails you will get an explanation of what went wrong.
Microsoft Flow provides hundred of ready templates that you can use for free, and you can create your own. You can learn more here https://docs.microsoft.com/en-us/flow/?utm_source=flow-sidebar&utm_medium=web