Hello everyone and welcome to my blog. Today’s blog shall focus on the following requirements.
- You need to check for missing property in JSON object and replace them with default value
- You need to replace null value with a placeholder value
This blog will demonstrate how you can achieve above requirement. For this blog, I will use a Flow with Manual trigger.
I have a variable varRequest. It’s a JSON array. The first object has three properties – FirstName, LastName and email. The second item in the array has the email property missing.
I iterate through the array and map each item properties to Dataverse contact record.
That’s easy and but remember our array’s second item does not have the email property. So when I run the flow, I get the below error.
Quite obvious isn’t it? After all the email property is missing from the second item and hence the error.
So what I need to do here? I need to check if the email property is present. If not then take appropriate action.
Power Automate has coalesce function. Using the coalesce function, you can check for null values or missing properties in an object and provide a replacement value instead.
Below is the expression to set the email property.
coalesce(items('Apply_to_each'), 'placeholder@sample.com')
Now when I run the flow, the flow is executed successfully.
Hope you liked this post. If this post has helped, you can buy me a coffee. Links on right pane.
For similar topics on Microsoft.NET and Power Platform, subscribe to my blog using the Subscribe option on right pane.
You will also like the below posts.
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.