PowerAutomate How to use optional arguments for Power Apps(V2) triggers|Do not generate errors when arguments are not set

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

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’]
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.

Related Articles

コメント

タイトルとURLをコピーしました