ForEach Property in #MicrosoftFlow JSON. With XPath? #microblog

I can't think of a way to do "ForEach Property Of JSON" in MicrosoftFlow or LogicApps - so I came up with this method that involves XPath.

Take example this JSON

{
  "a": 1,
  "b": 2,
  "c": 3
}

I want to do ForEach over the properties, so I need a way to convert this into:

[
  "a",
  "b",
  "c"
]

The usual suspects don't seem to work:

  • ForEach (only array)
  • Data Operations - Select (only array)
  • Array (wraps one object into array of one object)
  • CreateArray (wraps multiple objects into array)
  • Split - this could be used, but we'll have a hard time with nested JSON

Lets do XPath

XML objects must have one root element.  So let's wrap a root around our JSON

{
  "root": {
    "a": 1,
    "b": 2,
    "c": 3
  }
}

This next XPath splits each XML element under /root/ into a Nodeset (array of XML elements).

xpath(xml(outputs('Compose_2')), '/root/*')

Data Operations - Select

for each XML node, select just the name, map this for each node

xpath(item(), 'name(/*)')

Result

[
  "a",
  "b",
  "c"
]
for-each-json.png

I'm sure there'll be a better way one day.  But for now this will get me through.  I need this to be able to read nested JSON structures as part of my bigger plan.

Microsoft Flow makes everything Awesome. Yes, including InfoPath #microblog

This is a write up of various ideas and thoughts that I've shared over Twitter separately, but needed to be linked together and the example steps needs to be explained in a bit more detail.

Plan

On Reading many XML Forms in a Forms Library

Crazy InfoPath and PowerApps cross-app idea

with game state managed with Microsoft Flow, with JSON and XML dual binding.

API Management TIP

from @darrenjrobinson

Flow Details

In this Flow, we will do something fancy.  We will use the new Flow Management connector to list all the Flows in my environment.

Configure the HTTP Request method must be GET
The response must be XML - use xml() to convert JSON into XML output.

Check this in Postman

This is how you test a webservice.  You poke it with Postman.

check in postman.png

See this returns XML.

The rest is done in InfoPath

Connect it via REST connection.

data-connection.jpg
infopath-datasource.jpg
flow-run.jpg
infopath-run.jpg

This is pretty amazing.  InfoPath is listing in a repeating section the names of all the Flows I have in my environment.

Result

  • Because of Flow, InfoPath got server side superpowers it never had
  • Flow gain the ability to work with Managed Metadata today.  And so did InfoPath.  Only 7 years after MMD was shipped without InfoPath support.
infopath-meta.png

Flow is awesome.

Sending Custom Actionable Messages via Flow

Actionable Messages is a way that we can send a small bit of JSON within an email message, it gets picked up by Outlook (Web, App, Desktop, Mobile) and parsed as quick actions, or a way to collect additional information.

We can easily create Actionable Messages with Microsoft Flow, and this will extend our ability to build "disconnected human workflows"

Plan

  • Use MessageCard Playground to build our JSON
  • Send Actionable Message via Microsoft Flow as HTML embed

Message Card Playground

https://messagecardplayground.azurewebsites.net/

Use Message Card Playground to quickly try a few templates and see the JSON we need to build.  

Microsoft Flow's "Send with Options" as well as "Approval" actions use Actionable Messages - you can see the templates that's used.

Build a custom message with Flow

The Flow is quite simple.  A trigger, build a custom HTML string, then Send Mail with HTML.

flow.png

My test compose has this JSON

 <script type="application/ld+json">{
    "@context": "http://schema.org/extensions",
    "@type": "MessageCard",
    "originator": "Provider-id-from-developer-dashboard",
    "hideOriginalBody": "true",
    "themeColor": "0072C6",

 "sections": [
        {

            "heroImage": {
                "image": "https://minecraft.net/static/pages/img/addons-feature.8b0a274be963.png",
                "title": "This is the image's alternate text"
            },

    "title": "John how are your Flow and Minecraft doing?",
    "text": "Click **Learn More** to learn more about Actionable Messages!",
}],
    "potentialAction": [
      {
        "@type": "ActionCard",
        "name": "Send Feedback",
        "inputs": [
          {
            "@type": "TextInput",
            "id": "feedback",
            "isMultiline": true,
            "title": "It is doing great!"
          }
        ],
        "actions": [
          {
            "@type": "HttpPOST",
            "name": "Send Feedback",
            "isPrimary": true,
            "target": "http://..."
          }
        ]
      },
      {
        "@type": "OpenUri",
        "name": "Learn More",
        "targets": [
          { "os": "default", "uri": "https://docs.microsoft.com/en-us/outlook/actionable-messages" }
        ]
      }
    ]
  }
  </script>
<p>
Hello, please take an action.
</p>

A few notes - I did not register this JSON, so I'm only sending this to myself for testing.  This will ONLY work within my current tenant and internal email addresses.

Additionally, this doesn't seem to work on mobile Outlook.  I assume if I'm taking this to mobile I will need to submit and register the action.

https://docs.microsoft.com/en-us/outlook/actionable-messages/actionable-email-dev-dashboard

Make sure Send Email sends HTML

send-option.png

Results

I receive this in my Outlook (Web) mailbox.

email.png

What can we build with this?

In the JSON for Potential Action - we can specify HttpPost actions.  This is idea to chain into a new Flow action and start a new step.

I think about the "Pick your own adventure books".  Each time this runs, it presents me with the next chapter of the story, with buttons that lets me choose what's the next step to take to continue my journey.

So this is another piece of the tool that we can mix into our toolset.  

Difference between beta, edu and v1.0 of MSGraph #microblog

I find this interesting - source: digging around MicrosoftTeams powershell and Mikael Svenson's blog post on enabling Teams programmatically

What's funny, because what I found strange is when Mikael says this:

The creation of the group itself happens against the /edu/groups which I’ve never seen before, but that’s not interesting.

Because that's the bit I found totally interesting.  Why does the PowerShell need the /edu/ endpoint?
Hop over to Graph Explorer we can play with this:

msgraph-edu.png

 

Comparing different endpoint: v1.0

endpoint: beta

endpoint: edu

It becomes clear why we need the /edu/ endpoint.  It has this bit of information:

"creationOptions": [
    "SkypeSpaces",
    "ExchangeProvisioningFlags:481"
],

The hint that a Team is provisioned seems to be the flag "SkypeSpaces"

Interesting.

Naturally, one would ask.  So if I want to enable Yammer, Planner or PowerBI on an existing Unified Group.  Do I POST an update to creationOptions?

Very.  Interesting.

I'm speaking about Serverless Flow and Azure Functions at Collab365 Free Online Conference

collab365-watch-my-session.jpg

Have you heard about the virtual Collab365 Global Conference 2017 that’s streaming online November 1st – 2nd?

Join me and 120 other speakers from around the world who will be bringing you the very latest content around SharePoint, Office 365, Flow, PowerApps, Azure, OneDrive for Business and of course the increasingly popular Microsoft Teams. The event is produced by the Collab365 Community and is entirely free to attend.

Places are limited to 5000 so be quick and register now.

During the conference I'd love you to watch my session which is called : 

'Serverless with Microsoft Flow and Azure Functions'

Level up your mastery of Microsoft Flow. Switch to Azure Functions only when you need to. No doubt there will be many sessions on Microsoft Flow, introducing you to its wonderful merits and rough edges. This session is for the advanced users - we will see what Microsoft Flow really is, and bend it to our will.

If you join me, you will learn:

  • Master JSON in a Flow
  • Combining Azure Functions with Flow
  • Failure Recovery, in a Flow
  • How to handle Binary in a Flow
  • How to write HTML and generate PDF in Flow

Topic(s):

  • Azure Functions
  • Microsoft Flow

Audience :

  • Developer
  • Power User

Time :

  • Thursday, November 2 2017 10:00 AM (UTC)
  • Thursday, November 2 2017 09:00 PM (ADST)

How to attend :

  1. Register here.
  2. At the time listed above go here to watch my session. (you can also add me to your own personal planner from the agenda.
  3. Enjoy the demos and ask me questions, I'll put the templates up for download after the session.