Reputation: 1923
I am trying this out but I cant seem to get it to work.
In a Condition connector I'm doing this:
@contains(json(body('ParseCustomerDeltaXML')).newMembers[0], 'Member')
but i cant get it to work.
If it contains members it says true.
But if not i get an error:
InvalidTemplate. Unable to process template language expressions for action 'Condition' at line '1' and column '2706': 'The template language expression 'equals(json(body('ParseCustomerDeltaXML')).newMembers[0], null)' cannot be evaluated because array index '0' cannot be selected from empty array. Please see https://aka.ms/logicexpressions for usage details.'.
Upvotes: 0
Views: 10029
Reputation: 11
In my example I should check is element empty before fetching street data from element.
This works:
if(empty(body('Parse_JSON')?['results'][0]['addresses']), '', body('Parse_JSON')?['results'][0]['addresses'][0]['street'])
and this works too:
if(contains(['addresses'], ['addresses']?[0]), 'Do something', 'Or do this thing')
Hope that will help someone.
Upvotes: 0
Reputation: 1466
As indicated by the error message, the array you are trying to reference the first item of is empty. You want to make use of the safe dereference operator .?
Suppose newMembers
is an empty array. Then newMembers[0]
would fail, but newMembers?[0]
would succeed (and return null
).
In the specific scenario you are describing, you may need to use a nested condition as well (i.e. first check if newMembers is non-empty, and then check for membership).
To check for emptiness you can use the @empty()
expression.
Upvotes: 0