4

In Logic Apps, I have an expression:

coalesce(triggerbody().data.job_id,triggerbody().resource_id,'error')

I basically want to get the first one that is not null, however one of these does not EXIST in the json payload. I get an error:

'The template language expression 'coalesce(triggerbody().data.job_id,triggerbody().resource_id,'error')' cannot be evaluated because property 'data' doesn't exist, available properties are 'transaction_id, event_type, event_time, resource, resource_id, account_id, resource_third_party_id, request_user_type, request_user_id'. Please see https://aka.ms/logicexpressions for usage details.'.

If data doesn't exist, that value should be "null" and resource_id used. Any ideas what the expression would look like to have that behaviour?

1 Answer 1

3

The problem here is that you are trying to access to a property of a null element:

coalesce(triggerbody().data.job_id,triggerbody().resource_id,'error')

As triggerbody().data is null, Logic App can't evaluate triggerbody().data.job_id, you should check first if triggerbody().data is null.

Sign up to request clarification or add additional context in comments.

3 Comments

triggerbody().data doesn't exist in the payload deliberately- if it is not there, it needs to take from triggerbody().resource_id, but how do I do this.... I have tried if(equals(triggerbody().data, null), triggerbody().resource_id, triggerbody().data.job_id) but same error. Not sure how to check for undefined
Instead of use triggerbody().data, use triggerbody()?['data']. The question mark operator lets you reference null properties of an object without a runtime error. For example, you can use this expression to handle null trigger outputs: @coalesce(trigger().outputs?.body?.property1, 'my default value')
Bingo. Thanks so much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.