Compose action, dynamic content, and data conversions

By | January 7, 2020

Earlier today, a colleague of mine who tends to spend his days developing Power Automate Flows lately showed me something that seemed confusing at first. Now having dug into it a bit more I think it makes sense, but let’s see what you think.

Here is a Flow where I have an HTTP Trigger, a Compose action, Initialize Variable action, and “send an email” action:

image

When trying to add dynamics content to the email body, I see Compose action outputs, but I don’t see the variable. I also see “name” and “value” from the http request json payload.

What’s interesting about all this is that:

  • Presumably, email “body” is of “string” type
  • Compose action is of “any” type
  • “Name” and “Value” are of “string” type, too

 

As for the email “body”, I am not really sure how to verify the type there, but it’s a reasonable assumption.

I was not able to find  that statement about “Compose” action in the PowerAutomate documentation, but here is what Logic Apps documentation has to say:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-workflow-actions-triggers#compose-action

image

As for the Http request, here is the schema:

image

So, what if I changed the type of my variable to make it a “string”? I would not be able to use “body” from the Dynamic content to initialize it:

image

BUT. I would be able to use that variable for the email body:

image

Or I could just use “Compose”, since, the way I see it, it can take “any” type for input, and it produces “any” type for output. Which makes it compatible with any other type, and which is different from variables, since they are actually strongly-typed.

PS. Of course I might also use triggerBody() function to achieve the same result without using Compose, but what would I write about then?Smile

2 thoughts on “Compose action, dynamic content, and data conversions

  1. Shidin Haridas

    A more compelling reason to use ‘Compose’ over ‘Set Variable’ is performance!
    ‘Set variable’ puts a global lock on the variable, which means the execution time increases as the flow needs to wait everytime the variable is being updated by a parallel branch.

    Reference: John Liu’s session on the same at the Microsoft Flow Online Conference 2019. Unreal difference in execution times while using ‘Compose’
    https://www.youtube.com/watch?v=MvCcnlw6tjs&feature=youtu.be&t=30499

    Reply
    1. Alex Shlega Post author

      That “compose” is faster than “set variable” seems to make sense, since “set variable” is an update, and it has to be synchronized (sure that’s not something I’d think of until watching that video). On the other hand, compose output is a constant, whereas variables are updatable, so, for things like “counters”, compose is not much of an option. Totally agree those choices are more aligned with the “reasons why to use one over the other”. Type conversions, to me, is more like a caveat to be aware of:)

      Reply

Leave a Reply to Alex Shlega Cancel reply

Your email address will not be published. Required fields are marked *