Provide a Default Value with Coalesce Function - Microsoft Flow
    • Dark
      Light
    • PDF

    Provide a Default Value with Coalesce Function - Microsoft Flow

    • Dark
      Light
    • PDF

    Article Summary

    Building automation, or workflow, solutions can be challenging when you are expecting a value to be passed into your flow, but it never arrives. The result is missed expectations between the downstream system and Microsoft Flow. The downstream system is expecting a value, but when it doesn’t arrive it may fail mandatory field requirements or break dependent business processes.

    The Coalesce function allows flow makers to defend against this problem by checking to see if the input value is null. When this occurs, the Coalesce function will provide a default value that can be used instead.

    For example, take a business process that involves capturing contact details of potential customers. The agent that is collecting this information should be capturing a discount code that this potential customer should receive. However, if this does not occur, Microsoft Flow can inject a default value.

    The Coalesce function expects a field as an input. In this case, the field is called Discount, and is coming from our trigger. In the event a Discount field value is included in our trigger, then that value will be used. However, if that value passed in is null, then our value of 19% will be used instead.
    coalesce(triggerBody()?['Discount'],'19%')

    1-flow.png

    Testing

    We can test our scenario by submitting an HTTP Post from Postman and we will exclude our Discount field.
    2-request.PNG

    When our flow runs, our Coalesce function will detect our Discount field in our trigger is null and as a result, provide our default of 19%.

    3-output.png

    Conclusion

    The Coalesce expression is a strategy that flow makers can leverage to provide defensive programming by ensuring that downstream systems receive a value, even when the upstream system doesn’t provide one.


    Was this article helpful?