The curious tale of the result() function in Flow and LogicApps

Photo by Andrew Neel on Unsplash

Photo by Andrew Neel on Unsplash

I owe this blog post to several persons, so I will list their names first:


I woke up to Kevin’s reply and something jolted me awake. See, I didn’t know there was a result() function, and it really isn’t documented at all in LogicApps Workflow Expressions. I have most of the functions memorized and I have never seen it.

Before I saw Kevin’s answer, I actually assumed it was an old article and the function doesn’t exist anymore.

I tried searching for it - I still don’t find it.

The RESULT() YOU ARE LOOKING FOR IS NOT here

And it looks darn useful.

How often do you find a completely undocumented function in a language and the product manager doesn’t say it’s an incorrect function?

And that’s how I woke up early on Thursday morning.

Go read the example article and see what you think, before you continue. You only get one chance to ‘feel’ that excitement I had when I read the article, that expression, if you continue reading, I will spoil that for you. Go read it and wonder, may be even stop now, and go explore it yourself and then come back :)

We have work to do. If you like, I want to compare notes, my notes are below.

Plan

  • Experiment

  • Understand

  • Apply

Experiment

So we create a Flow and immediately add two Compose to test the result function.

TALK about a ERROR message wow

This isn’t a completely crazy error - it tells me a few things

  • result function exists

  • it expects “actions of type ‘Enumerable < actions > ’

  • that looks like it expects actions that contains actions

Try the example in the docs, we do get it to work and can see its outputs.

Wrapping our test action inside a Scope, result(‘Scope’) returns actual real data.

It is a treasure trove of runtime information. Nested, grouped, runtime information.

Understand

Scope isn’t the only block in Flow that contains other actions, let’s try a few more of them

The Do Until block returns the final block and the repetitions.

The Apply to each block is extremely interesting. Because it returns outputs from every iteration. It is very very long.


Applications

The first application is to use this as a generic catch-all error.

Here’s a fancy Flow that tries to sometimes run a divide by zero.

This one is similar to the Logic Apps blog post - I use a fancy HTML table to show all the rows at once.

The second application is to use this as a very fast array append

This is a very common scenario where we want to group up individual apply-to-each results into an array for use after the apply-to-each block.

On one side - we have the traditional method of appending a line of result to a shared global array variable.

On the other side - we have apply-to-each and then we just output the result we want in a compose action. We use a Select after the apply-to-each to map the output from the result() function.

Apologies - the left/right of these screenshots toggled when I save and reload the Flow. So embarrassingly I have some of the pictures where result method is on the left, and other picture where the method is on the right.

Please refer to the two branches as "(result method)” and “(append method)”
If confused - please check the name of the apply-to-each block in the picture.

Change the apply-to-each to run in parallel


In parallel, the result() function is so amazing.

The 3rd Application is to run complex Select, using Apply-To-Each

and then use result() to gather the results, all without defining an array variable. This means you can run fairly complex apply-to-each block within a scope.

Bug

Because result() is a function that the Flow editor does not understand, it will save and run correctly, but the editor may mistakenly translate the expression to a string.

The main problem is that you may have a working Flow but when re-opening the Flow the editor turns an expression into a string and breaks the Flow, because it doesn’t understand that result() is a valid function.

I hope this bug is fixed soon.

Summary

result() is a cool function, and has some very important applications.

Make a wishing wand - why we need a MicrosoftFlow Custom Connector for MSGraph $Batch

A question that has been in the back of my mind since my late night demo of building a Microsoft Flow Custom Connector for Microsoft Graph is this.

I focused on the "how" - because I wanted to show that the whole thing can be done in about 10 minutes.  And I didn't want to skip steps like "oh here's how you register an Azure AD app".

 

But (and this is my fault, I did only ask for 10 minutes) I should have spent some time to talk about the "why"

Why do we need this?  What problem does this solve?

Why does John think this is super special?

This is special because, a $Batch connector is a "Send HTTP Request to MS Graph" as me.

It is a wishing wand that grants wishes. Creating MSTeam is a wish. We didn't build a wish. We built a wishing wand. Then we waved it around.  MS Teams API currently is delegate permission only, so we call it through a $batch connector.

Planner API is delegate only.  Any time you see a delegate permission MSGraph you remember you have a wishing wand.

The Ingredients:

Microsoft Flow and Logic Apps has concept of connectors (these are essentially API definitions) and connections (these are instances of connectors bound to a resource as well as cached automatic authentication)

A Flow is a JSON description of how actions and triggers on the connection are chained together to perform automation.

We do have a general purpose HTTP action, and it works very well for app-only permissions that needs client-id/client-secret or client-cert.  But HTTP action is not backed by a connectors framework so it can't remember credentials.

To build a general purpose tool and remember credentials for Microsoft Graph, we have to build a custom connection.  This is basically a swagger API file that tells Flow and LogicApps what APIs exist on the resource.  In the case of MSGraph, that list is enormous.

The Recipe:

The crazy part though, is MSGraph provides a $batch endpoint, so the recipe for building the magic wand is simply this:

  1. Build a custom connection with one method - $batch - this is a POST
  2. Pre-authenticate it with a delegate permission
  3. Wrap requests (1 or many) as a JSON array and call them via the $batch connection.
  4. We have a magic wand

Agenda for the September community call included Microsoft Graph updates, Microsoft Graph and Microsoft Teams, and custom connectors for Microsoft Graph $Batch

Where do we go from here?

I demoed this with a Manual button trigger.  Jeremy mentioned (in the video) that this can easily be a SharePoint trigger.

This can also be a HTTP Request trigger, turning your Teams Provisioning into one simple HTTP Webservice.  You can hook that up to external systems, PowerApp or a bot.

A technical note

Sometimes you discover you need extra permissions on that Azure AD app.  We do this by going back to Azure AD portal and add the extra permissions.  You can "grant permission" through the AAD portal.

If the cached connection in Flow refuses to work, I find that we may need to right-click on the custom connection and re-authenticate.  Sometimes this requires us to switch to a different user then switch back.  Because Azure AD dynamic consent is just so hard to do.

But it will work.  Just need to toggle a few times.  I do this a lot.

Resources

 

Office 365 Saturday Adelaide - 2018 September 15

sps-adelaide.png

So it is said - there's always a SharePoint or Office 365 Saturday every Saturday around the world.

 


O365 Saturday Adelaide / SPS Saturday Adelaide

In less than two weeks, we'll converge in Adelaide Australia for September 15 2018 SharePoint and Office 365 Saturday.

This is a free event (held at Microsoft Adelaide this year) for Office 365 and SharePoint experts, developers, admin and powerusers to converge and talk about Office 365.

https://www.meetup.com/O365-Saturday/events/254139366/

This year I'm presenting an ever evolving talk around Microsoft Flow and what it can (and SharePoint's old Workflow platform can't do).

Hope to see you in Adelaide!

A small favour - share this with two people

Every year we reach out and people that come to the event tells us it's a great event but they wish they know about it earlier.  So here's our small ask:

If you are in Adelaide, please come, and please tell two other colleagues about this.
If you aren't in Adelaide - but you have colleagues in Adelaide, please tell them about this event.

 

 

 

Microsoft Graph Community Call September 2018 - $Batch and Flow

I wanted to write a quick blog post letting everyone know I've put my hands up to present a 10 minute demo on using a Custom Connection for Microsoft Graph $Batch in Microsoft Flow.

Custom Connection = Swagger = WSDL

In Microsoft Flow, Power Apps or Logic Apps, a Custom Connection is a Swagger/Open API definition that allows these low-code solutions access to a well defined API, so it knows what to call and how to call them.

For old API guys that knew what a SOAP Webservice looked like, this is the WSDL that tells other systems how to use this service.

In general, calling Microsoft Graph with App-Only Permissions requires only a client-id and client-secret pair, and we can do it directly via the HTTP action without needing a custom connection.

When we do need to create a custom connection, that's usually because we need to call something with Delegate permissions

Why Flow - Connectors Framework

One of the hidden supper power of Flow and Logic Apps is the connectors framework, which cache, renew and manages connections across various different APIs and auth methods.  

This means - you actually don't need to write any of this code.  Repeat - as a developer, you don't have to write code to manage auth.  Auth is encapsulated away and auth code is no longer your concern.

Why $Batch

You'll have to see the demo (I'll update this later).  Hey, I can't spill all the beans in one blog post.  This is a tease.

The result

If you want to automate any delegate-permission API calls on Microsoft Graph, then Microsoft Flow is the easiest way to do it - far easier than writing code, and this is considered a low-code solution, it's crazy nuts.

Resource

Link to the recording will be updated here once presentation is done and uploaded.

The future of Flow Studio - Trial

Hi everyone.  This is somewhat serious, and I really need your feedback.

I wanted to write this down and project my intentions clearly and well in advance.  This is something I really would want feedback regarding the future of Flow Studio.

 

Flow Studio today

I love working on Flow Studio, and I heard feedback all the time that there's more I can do with it, there is so much more.  It is always my intention that if I can make it into a product offering - it can supplement my income and I can wholly devote more working days to it.  It is very fulfilling work but very very tiring to work weekends and evenings and have a head full of grey hair from lack of sleep.

A few weeks ago - I implemented Google Analytics to try to figure out which feature area people are using that I need to improve on.  If you are interested I can share the results.  But (to my surprise), I'm now tracking 40 active users per week.  When I last guesstimated 3 weeks ago before I implemented analytics - I thought I had 10 recurring.

The most used activity is Expand - of course we all want to see our Flows, what's been running, and more importantly, what's been failing.

 

Immediately: announcing a new web-3.0 URL

Here's a new thing.  You can use this shiny new URL that makes this a web 3.0 application.  A new URL means we are in serious business.

https://flowstudio.app 

The old address will continue to work, and they both map to the same application at the moment, in the future I consider switching the old URL to an insider/test build.

 

Flow Studio tomorrow

Flow Studio is free.  Whether you add a subscription or not.

The current functionality, navigation, filter, sort, tag will all sit in the Flow Studio base product and provided for free indefinitely.

For the subscription, my thinking is to chase after two particular Stories:

The Flow Studio Professional scenario and the Flow Studio Administrator scenario

Flow Studio will exit Open-Alpha status today, from tomorrow it will be Open-Trial status.  Everyone is on trail status.  There's no subscriptions built yet so it's just a name that implies there's more stuff later.  I will also start to label functions as Pro or Admin.

 

Flow Studio Pro

Flow Studio Pro is a subscription offered for Professionals, Consultants, Makers.  The main work here is to help you make more Flows, quicker and better Flows.

  • I am thinking to move the Edit JSON capability here - because I think the users that really benefit from this feature are super Flow users and will be happy to pay a small subscription.  This is also an area that I think I'll need to build more protection to help people feel safer modifying their Flows and not worry about breaking a Flow.
     
  • I'm thinking to offer a rudimentary backup/restore to give people some assurances.
     
  • The ultimate goal is to provide more Power User focused features.  Do you know you can rename actions with Flow Studio?  (this feature will also move under PRO)
     
  • I am thinking to charge US$5/m per account (email) or $10/m for 3 emails (I think the 3x offering is better suited for teams or for consultants that work on multiple projects - you can choose which 3 emails as you please)

    I have no idea if that's too little or too much.  You have to tell me.  I also think it is a subscription you can turn off and on as you like - if you aren't using Flow anymore on your project just stop the subscription and resume it later. 
     
  • Flow Studio doesn't go into your environment and delete anything when you unsubscribe.  Don't worry!
     
  • Without a subscription the Pro and Admin functions are disabled.  Flow Studio will continue to function.

 

Flow Studio Admin

The Flow Admin scenario is a subscription offered for Administrators - the main work here is to help you see all the Flows within your organization, set up triggers, reports and governance policies when things happen.  Turn off Flows when it exceeds run limits, when it uses specific connectors, what happens to the Flow when its owner leaves the organization etc etc.  What happens when a Flow fail?  When it fails a lot?

  • I am thinking $30/m for Flow Studio Admin - the Flow Admin may need Flow Plan 2 for access to the /admin REST APIs.  So I'm cautious what is coming out of the box with Plan 2, and what I plan to build as extras on top.
     
  • Ultimately, I want Admins to have better visibility into what they have running in their environment, help them build triggers and governance flows (even if they unsubscribe later) and help them feel comfortable configuring Flow to suit their business.
     
  • There will be trials for all these subscriptions so you can see the functionality.  Flow Studio Admin is aimed to be purchased by an IT department and has visibility into thousands of Flows.

 

Variables

US$5, $10 and $30 are monthly recurring subscription costs.  You can switch them on or off from month to month.

But I really want to know what you think.  Ask yourself this: if Flow Studio is $5/m will you buy it now, or will you not.  Tell me what you think.

 

Please tell me what you think

This is really important to me.  Is it too cheap.  Is it too expensive.  Does this help you.  Does this not help you.  What are your worries.

If you are a fan of Flow Studio or a fan of building start ups, I want to hear from you.

If you think Flow is wonderful but nobody should have to learn expressions - I really want to hear from you.  How can I help you, for only $5/month.


My lines are all open:

https://twitter.com/johnnliu
https://www.linkedin.com/in/johnnliu/ (please mention re: flow studio when connecting)
https://github.com/johnnliu/Flow-Studio-Issues/issues

or comment below