cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

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
Highlighted
New Member

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

8 REPLIES 8
Highlighted
New Member

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

Highlighted
Kudo Kingpin
Kudo Kingpin

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'] ,'')

 

Highlighted
Advocate II
Advocate II

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

Highlighted
Kudo Kingpin
Kudo Kingpin

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

Highlighted
Kudo Kingpin
Kudo Kingpin

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.

Highlighted
Kudo Kingpin
Kudo Kingpin

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'])

  

Highlighted
Advocate I
Advocate I

Re: Check triggerBody for existence of a property without crashing

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

Super User
Super User

Re: Check triggerBody for existence of a property without crashing

Thanks @LaurenceL , exactly what I was looking for. 

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors
Users online (3,658)