Note that I got a little stuck on the use of optional arguments for the Power Automate trigger “Power Apps (V2)”.
Option argument
Arguments that can be set in Power Apps (V2) triggers can be “Optional (optional)”.
The argument can be made optional by selecting “Make the field optional” from the menu.
This time, using that optional argument, we created a flow that returns the string if the “str” argument is set, and returns the message “not set” if the “str” argument is not set (when null).
Works when called with arguments
First, let’s call this flow from the Power Apps side with set arguments,
Works fine.
Error occurs when calling with no arguments set
Next, let’s call it without arguments,
An error occurred.
Checking the error on the Power Automate side, the following message is returned.
The template language expression ‘triggerBody()[‘text’]’ cannot be evaluated because property ‘text’ cannot be selected.
Workaround: use the “?” operator
I was looking for a solution and found the following article.
Button Flow Optional Parameters
I have a button flow that accepts two parameters. Both parameters are optional. InspectionId (int) and InspectionMonth (...
The article says that you can put the “?” operator in the triggerBody expression when referencing optional arguments. operator in the triggerBody expression when referring to optional arguments.
triggerBody()[‘argument name’]
↓
triggerBody()?[‘argument name’]
triggerBody()[‘argument name’]
↓
triggerBody()?[‘argument name’]
So the expression that calls the argument “str
Added “?” operator is added.
Save the flow and run it again,
It worked successfully!
Operator “?” in JSON
It seems that using the “?” operator to return “null” instead of “error” if the referenced field does not exist.
So this time, when I called without setting any arguments, Power Automate seemed to work correctly because it treated the call as “null” instead of an error in the flow.
※Reference Articles
Use of Question Mark(?) in expressions
Could someone explain why some expressions contain a question mark in them while others not? What is the difference be...
コメント