In this #PowerShot I will show you how to pass a 'Null' value as an input while using a manual trigger in MS Flow. Currently while configuring a user input for a manually triggered flow, if you set the input as optional and the user does not provide an input, the flow fails with the following error:
So when the flow is triggered, the output of the trigger should contain the 'text' parameter in the body. If the flow is triggered without any user input (when the input field is optional) this 'text' parameter is not included as a part of the body and hence the above error.
Resolution: There can be a lot of other approaches to solve this issue, and the easiest one of them is to use a '?' while referring to the input property. You can use the below expression to assign the variable or the compose action:
triggerBody()?['text'] when there is a single input and for multiple, you can just keep incrementing the property as triggerBody()?['text_1']. (Thanks to @johnnliu for this tip)
And then here is one that I found can be implemented using the triggerbody() attribute from the expression editor/ if you directly want to choose the value from the dynamic selector.
If there is only one input field expected, use a compose action and use the below expression:
Expression: if(empty(triggerBody()),null,triggerBody()['text'])
Explanation: This checks if the trigger body is empty and if so, the value will be set to null and if not, it will be set to the input provided by the user under the 'text' parameter.
If you have more than one optional input, you can check the parameter name and it will be sequential as 'text_1' and use the expression below for the compose action:
Expression: if(contains(triggerBody(),'Text_1'),triggerBody()['text_1'],null)
Explanation: This checks if the trigger body contains the 'text_1' parameter and if yes, sets the value to the user input and if no it sets the value to null.
Here we are updating the value for a variable as an input from the user or as null if it is a null value. In case you want to replace it with some other value you could replace the 'null' string from the above expressions and place that string over there. In case you go with the '?' approach, you could use the coalesce() function that checks if the value is null and you can provide the alternate value accordingly.
In this post, we saw how to use the tirggerbody() function from the expression editor to check if there was a value passed by the user or not. Similarly, you can use the triggerOutputs() function to get any trigger outputs/ headers as a part of the trigger being used and perform any further operations on it based on the use case.
Note: The same can be followed for triggers where manual inputs can be configured.
I hope you found this interesting and it helped you!
Comments