Showing results for 
Search instead for 
Did you mean: 

Add an ability to check if property exists in an object

It seems that MS Flow has no ability to properly check if an object exists.


Let's have an example with an out-of-the-box Approval action:



If an approver does not leave a comment and simply approvers or rejects - our code that tries to read the comments will fail.


Worarounds that do not work:

  1. Using condition step with `empty(body('Start_Approval')['comments'])` Because it will still fail
  2. using equals null: equals(body('Start_Approval')['comments'], null) This will also faild
  3. using contains function: `if(contains(body('Start_single_approval'), '"comments": '), body('Start_single_approval')['comments'] ,'')` - Because word "comments" can appear in different properties and overall it's a bad practice

Terrible workardound:

- Using Try-catch-finally scopes 


Please, implement a proper function that will check if property of an object exists. Example:





More info about the issue is here

Status: New
Advocate I
if(empty(body('ApprovalByAnyDirector')?['comments']), 'None', body('ApprovalByAnyDirector')?['comments'])


This does the trick. Notice the question mark.

Kudo Collector

Thank you very much! (for posting and coming up with the ? solution)