cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LaurenceL
Level: Power Up

Check triggerBody for existence of a property without crashing

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?

1 ACCEPTED SOLUTION

Accepted Solutions
LaurenceL
Level: Power Up

Re: Check triggerBody for existence of a property without crashing

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

View solution in original post

7 REPLIES 7
LaurenceL
Level: Power Up

Re: Check triggerBody for existence of a property without crashing

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

View solution in original post

Re: Check triggerBody for existence of a property without crashing

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
Level: Powered On

Re: Check triggerBody for existence of a property without crashing

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).

Re: Check triggerBody for existence of a property without crashing

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

Re: Check triggerBody for existence of a property without crashing

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-obje...

 

Please, upvote if you face the same problem.

Re: Check triggerBody for existence of a property without crashing

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
Level: Powered On

Re: Check triggerBody for existence of a property without crashing

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

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 52 members 3,352 guests
Please welcome our newest community members: