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:
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:
As for the Http request, here is the schema:
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:
BUT. I would be able to use that variable for the email body:
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?
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
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:)