Sunday 4 March 2018

5 ideas for using Flow in your applications

Like many others, my team and I have been doing more and more with Microsoft Flow recently. It’s true that it does have some limitations, especially when you get into longer running processes which are more “state machine” than “take this set of actions” (or you want to understand more around update of items in SharePoint, or respond to delete events, rather than new), but overall the capabilities are incredible. In particular, it’s the connectors to other services that make Flow – and the resulting set of things you can do with them. Chatting to some other developers recently, it occurred to me that lots of Office 365 technical people are probably unaware of what Flow can do these days - and so that motivated this article. My list of cool things you can do for this article is:

  • Send a message on Skype for Business
  • Post into a Microsoft Team
  • Add a row to Excel
  • Create an Office 365 Group (via a call to the Graph)
  • Send a push notification to a mobile device

A few days earlier, I found myself doing strange things in a Flow I was building – I just needed to do some basic debugging to find out why my process was going down one branch, when I expected to be going down another. Why was the value I was testing in my “if/else” condition not what I was expecting? I figured I would add some quick and dirty logging somewhere so I could get better visibility of things (and probably remove or change this later) – but then I couldn’t find something logical to log with. My initial thought was to use Azure Application Insights – I recently talked about using this in intranets and page widgets to track events in your code i.e. particular actions that users take. How often is your app launched? How often are users clicking that special button? How many users ever switch to the second tab of your user interface? Or, perhaps in site provisioning – how many sites are being requested, and how long do things take? I figured that you could log to App Insights at particular points of your Flow, and that would be a great way of analyzing the most common path through a Flow, or perhaps doing some debugging during the build.

Unfortunately, there is no “Track event in Azure App Insights” action yet :(

I added a UserVoice item here if you also think this would be a good thing and feel like voting.

Anyway, this led me to having some fun with other possibilities – you could use them for quick and dirty debugging like me, but I think there are a lot of true business possibilities here and so it’s worth being aware of them.

Send a message on Skype for Business

This one could be useful if a person/team needs to be notified *immediately* when something is added or changes somewhere in Office 365, and for some reason an e-mail notification isn’t a good fit. Arguably this one works best if the recipient is a desktop/PC user – later I talk about options for notifications to mobile workers. Anyway, it certainly gets the user’s attention, and it can be configured in your Flow very quickly. Here’s the end-user experience:

SNAGHTMLae4a2ce

SNAGHTMLae8cb91

Here’s what it looks like in Flow:

SNAGHTMLaed16de

Post a message to a Microsoft Team

But enough of Skype for Business, the future for most organizations (in the Microsoft cloud) is Teams of course. As you’d expect, there’s good integration between Flow and Teams. Saying that, it’s not currently possible to send a chat message in Microsoft Teams, but we can post to a channel – which is arguably more useful in the real world. Here’s what it looks like in Teams:

SNAGHTMLaf32cbb

Here’s what it looks like in Flow:

SNAGHTMLaecbb70

Add a row to Excel

Of course, half of the world’s critical processes are still running in Excel. Fortunately, you can easily use Excel as a data source from Flow, whether that means reading from or writing to workbooks – it’s trivial if the Excel file is somewhere in Office 365. In the example below, I’m adding a row to an Excel workbook every time an expense report is submitted to SharePoint. This could be used by a finance team for reporting or to help with some month-end processes perhaps. The end result is an Excel spreadsheet which is being built up automatically over time, and I can pull details from the SharePoint item into Excel:

SNAGHTML532992d

Here’s what it looks like in Flow:

SNAGHTML528ddc8

SNAGHTML5296150

SNAGHTML528413a

HTTP call to the Graph (with AAD auth) – e.g. to create an Office 365 Group

Some really interesting possibilities come with calling the Microsoft Graph from Flow. Obviously the Graph is the gateway to all things related to mail, calendar events, contacts, documents in SharePoint/OneDrive, Planner tasks, Teams and more. In this case I’m focusing on Office 365 Groups. How about a way to control Group requests and creation through a SharePoint list with approval? I implemented this in 20 minutes flat, and I think many organizations in Office 365 would get a lot of bang for buck from such a process. The ingredients are:

  • A SharePoint list for users to request a new Office 365 Group – this provides the form
  • A Flow with a ‘Start an Approval’ action – this provides the controlled creation/approval by an administrator step
  • A HTTP action added to the Flow (when it goes down the “approved” condition branch) – this calls the Graph, in this case, a POST to the /Groups endpoint with the details of the Group to be created
    • An AAD app registration for to authenticate with the Graph – this must have permissions to create Groups (e.g. Group.ReadWrite.All)

So, if you imagine a SharePoint list where items get added:

SNAGHTML6cf84d

We add a Flow to respond when a new item is added to the list, and somewhere in there we add the simple HTTP action (e.g. after an approval step):

SNAGHTML61e70c

We configure this to point to the correct URL in the Graph API, and pass the appropriate JSON for Group creation:

SNAGHTML667c82

There’s actually a bit more to it than that – we need to specify authentication details for the call, in this case specifying the Client ID and Secret for our AAD app registration which has the appropriate permissions (done separately in the Azure portal):

SNAGHTML6a6369

..and then, when an item is added to the list and it is approved by an admin, the Group is created along with the corresponding mailbox, calendar, SharePoint site and so on:

SNAGHTML6ed412

image

Not bad for 20 minutes work! Of course, the ability to easily call the Graph means you could do a bunch of things – I can certainly imagine lots of business processes where it would be useful to do things like:

  • Create a calendar item
  • Create a task in Planner
  • Update a user profile
  • Add a new contact

..and so on. A quick look at the Graph documentation should give you lots of ideas.

Send a push notification to the Flow owner on their mobile device

What if you need to get an immediate notification out to some users or administrators who are typically mobile or out in the field when something is changed in Office 365, and e-mail or SMS aren’t the right solution? We’re used to getting push notifications from certain apps on our phone/tablet these days, but developing a custom app and getting this in the hands of all your users can be expensive and time-consuming. If you can get the iOS/Android versions of the PowerApps or Flow mobile apps in their hands instead – and remember, users can install those right now from the respective app stores – then you can send push notifications to these apps very easily.

Caveats!

OK, so there are some caveats with this one, partly because there are two ways you can send push notifications. The caveats are:

  • The standard Flow push notification can only send *to the Flow owner*
  • The PowerApps push notification can send to anyone, but your app users need to be on a premium (paid) plan – remember this doesn’t necessarily need to be everyone in the org though

It’s also worth considering that if you need a notification that something needs to be approved by the recipient, Flow can do something even better for that – Flow approvals work great in the Flow mobile app. The task details are shown fairly clearly, with big “Approve” and “Reject” buttons:

SNAGHTMLd17167a

Nothing special is needed for this, just regular use of the Flow ‘Start an Approval’ action. If the recipient has the Flow app installed on their device and is logged-in, they’ll receive the notification and be able to approve/reject extremely easily from inside the app.

But what about other types of notifications? Perhaps someone has submitted something, and you need to confirm to them that it has been logged and a process has been started? Well, if you can use the PowerApps push notification option, this works great and you can even prompt the user to open your PowerApp (and pass parameters to load a particular item/take the user to a particular screen etc.):

SNAGHTML109d618a

When the user opens the notification, your particular PowerApp can open. Here’s what it looks like in Flow:

SNAGHTML109f23cb

Pretty nice stuff really.

Summary

I think it’s a good idea for all developers, architects and technical business folks working in Office 365 to be aware of the possibilities of Microsoft Flow. There’s a significant leap forward here in terms of what can be accomplished for the amount of effort involved – and so many organizational processes can benefit from this stuff. I’ve presented 5 ideas here of some things that might be useful, but I’m focusing mainly on taking other actions in or communicating via Office 365. Consider also that Flow has a LONG list of connectors to 3rd party applications – and although all the top enterprise productivity vendors have a similar list, I don’t believe anyone is taking it as far as Microsoft are. The image below shows a small selection (just those starting with letters P to W!):

SNAGHTML10a176b4

Even in this set you can see Salesforce, ServiceNow, WorkDay and lots of other enterprise systems.

I think some of this stuff is killer for Office 365 personally. Happy process building!