Manually Trigger a Flow action is, without question, one of my most used triggers ever. Although it’s super useful to have Flows triggering automatically, it’s also super useful to have a Flow that you can trigger manually, and it does something for us.
I will write an article about this, but you’ve seen by now that I like to create a lot of “sub-flows” or “aux-flows,” as I call them, where I put common tasks. So, for example, if you go to my cookbook, you’ll find some Flows that you can import triggered by a “Manual Trigger a Flow” trigger.
So let’s explore it a bit further.
Where to find it?
The “Manual Trigger a Flow” is part of the default set of triggers in Power Automate. The other ones are automated (all that react to some changes) and scheduled (trigger periodically regardless of the changes).
If you’re creating a Flow from scratch is usually the first recommendation on the list.
Here’s what it looks like.
Once you add the trigger, you can add input parameters. These are super useful when your Flow does something that needs outside information. Think, for example, a Flow that parses a CSV file. You would want to provide to the Flow, at least, the location of the CSV file to process. To do it, press the input, and you’ll have many types to choose from.
To start, let’s pick the “Text”. This is what it looks like.
In all input parameters, we have the “Input” and the “Text”. The “Input” is the name that you’ll find in the dropdown list on any Flow action. For example, let’s change the “Input” to “File to Parse”. Here’s what it looks like inside a “Compose” action.
Now let’s say you have many values that you want someone who calls this Flow to pick. For example, let’s say you’re adding data to a list but only want to add it to existing lists. So you can “Add a drop-down list of options” like this.
Now, instead of allowing people to insert random strings, you can define the range of acceptable values.
Let’s test it.
As you can see above, there’s a defined list of values that you can pick. You can also have the same above but allowing your users to select more than one value.
Here’s what it looks like:
We have the same dropdown as before but now with checkboxes to select the items you want.
Making things optional
Not all fields are always required, so Power Automate’s possibility to make them optional.
Making fields optional is tricky because Power Automate won’t return the field if it’s not filled in. So, to make things a bit more visible, let’s create a new date field and make it optional. Also, let’s add a “Compose” action so that we can see the value provided.
We would expect two things:
- To have a value if the “Trigger date” is filled-in
- Empty if the “Trigger date” is not filled-in
This is not what happens. If the value is filled in, we get a value.
But if the value is not filled in, we will get an error.
Unable to process template language expressions in action 'Compose' inputs at line '1' and column '6037': 'The template language expression 'triggerBody()['date']' cannot be evaluated because property 'date' doesn't exist, available properties are 'text, boolean'. Please see https://aka.ms/logicexpressions for usage details.'.
Why? Because the value is not filled in, Power Automate won’t create the object “Trigger date”. So if we try to access it to get the value, we will get an error because it doesn’t exist. This behavior is counter-intuitive, but I wanted to show you in case you get the same error.
How to check optional values?
I’ll go over this in more detail in another article, but for now, you need to understand that the triggerBody() contains all the parameters that have values. Since the default behavior is for the parameters to be mandatory, we’re always used to have values, but that is not true for the optional values.
When we pick the element from the “Dynamic Content” list, we’re doing the following:
We’re telling Flow that we will get a value for sure. If the object
date doesn’t exist, then Flow will return an error since it can’t find anything. You need to tell Power Automate that the element you’re trying to fetch is optional to solve this issue. To do that, here’s the new code:
The difference is all in the question mark. It indicates that we’ll try to find a value, but that’s ok since it’s optional if we don’t.
You can’t do this by picking the element in the “Dynamic Content” list, so you need to write it yourself. Since we have the value from the error, we only need to add the question mark, and we’re good to go.
Here’s what the Compose action looks like:
And here’s after we run the Flow.
No more errors.
Trigger the Flow
Since we’re using “Manually trigger a Flow,” we need to do something for it to run. There are 3 ways to do it:
- First, call it directly in Flow.
- Use the mobile app and trigger it
- Call it from another Flow.
To call from Flow, you can use the top button to Run or the dots next to the Flow’s name. You’ll be prompted if you need any parameters. In the mobile app, you can use the “Button” tab that will display all the triggers.
I want to explore a bit further how to call it from another Flow. Using the “Run Child Flow” action, you can call a Flow inside another if you’re using solutions. Let’s have a simple trigger with a “Compose” action.
And now, let’s create another Flow and call this one.
As you can see, Power Automate is smart enough to understand the parameters that the child Flow expects and display them to you. There’s a lot of advantages to doing this:
- First, you always know what Flow you’re calling.
- Second, the parameters are always defined, so there’s a lower chance of incorrect values being provided.
- They are reusable. Child Flows can be called multiple times, and in multiple Flows, so it’s always good to keep common actions in child Flows.
The major limitation with this trigger is that you can only call it from other Flows if it’s inside a solution. Also, you can only add a Flow with this trigger if it was created inside a solution. So if you create a Flow outside a solution with the “Manually Trigger a Flow” trigger, you can’t add it anymore to the solution.
Here are some things to keep in mind.
Name it correctly
The name may not look important since it’s a trigger, but I would advise naming it as descriptive as possible. There’s a lot of o information that the name can provide, like, generally, what information we’re expecting, if the Flow is to be used as a button, for example. Always build the name so that other people can understand what you are using without opening the action and checking the details.
Always add a comment.
Adding a comment will also help to avoid mistakes and fix issues in the future. Having a note with the desired types of values and why some of them are optional, for example, is essential information to define before you start building your Flow. In addition, it’s important to enable faster debugging when something goes wrong.
Back to the Power Automate Trigger Reference.