web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Check triggerBody for ...
Power Automate
Answered

Check triggerBody for existence of a property without crashing

(1) ShareShare
ReportReport
Posted on by

Hi - how do I check for the existence of a field in the triggerBody? I cannot check for null or empty as this crashes if the property actually doesnt exist. These do not work @equals(triggerBody()['partnerId'], null) or @empty(triggerBody()['partnerId']) if "partnerId" doesnt exist. I need to check as my HTTP request can occasionally not send the required property.

 

Any ideas?

Categories:
I have the same question (0)
  • Verified answer
    Community Power Platform Member Profile Picture
    on at

    this was solved by using the @contains function as in @contains(triggerBody(), 'partnerId')

  • DenisMolodtsov Profile Picture
    317 on at

    It does not really work for me

     

    This still fails because genius MS Flow tries to evaluate `body('Start_single_approval')['comments']` expression even if you wrap it with if(contains()) 

     

    if(contains(body('Start_single_approval'), '"comments": '), body('Start_single_approval')['comments'] ,'')

     

  • MasterOffice365 Profile Picture
    184 on at

    I also have the same issue where the contains function doesn't work checking for the existance of a property in an array. Exactly the same logic (i.e. within an If statement).

  • DenisMolodtsov Profile Picture
    317 on at

    I could not find anything that can properly check for properties to exist...

     

    The only ugly workaround is to create 3 scopes:

    • Try  - try to access a property that might not exist. If it does not exist - we fail and go to the next step
    • Catch - Run only if the previous scope fails
    • Finally - Run in any case

     

    Scopes.png

  • DenisMolodtsov Profile Picture
    317 on at

    Created request for a function that check if property exists: https://powerusers.microsoft.com/t5/Flow-Ideas/Add-an-ability-to-check-if-property-exists-in-an-object/idi-p/191908

     

    Please, upvote if you face the same problem.

  • DenisMolodtsov Profile Picture
    317 on at

    I haven't tested it yet, but @xilef suggests using '?' approach. Seems promising to me:



    if(empty(body('ApprovalByAnyDirector')?['comments']), 'None', body('ApprovalByAnyDirector')?['comments'])

      

  • lvg Profile Picture
    15 on at

    Tried it...even tried with not()...does not work

  • Community Power Platform Member Profile Picture
    on at

    Thanks @LaurenceL , exactly what I was looking for. 

    contains(triggerBody(), 'thing') worked great for me. 

  • Community Power Platform Member Profile Picture
    on at
    if(empty(body('ApprovalByAnyDirector')?['comments']), 'None', body('ApprovalByAnyDirector')?['comments'])

    This expression is not foolproof solution, since it will return 'None' not only when there is no comments property, but also when comments value is empty string. But for some use cases it may be the most compact.

  • 3tsolutions Profile Picture
    94 on at

    I wrote a solution to handle missing properties of an object, if it helps

    LINK

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 519 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 296 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard