Share via

Using the "items" function with an IF statement

Anonymous
2022-01-10T09:44:46.513+00:00

I'm using a Logic App that contains a FOR EACH called "For_each_Item_in_Items". The FOR EACH is running on an array from an SQL query. I'm interested in a column called "Exists" which contains a string of either "ABC" or "DEF".

To get this value I'm using a "Set variable" action as follows:

@{items('For_each_Item_in_Items')?['Exists']}

This works.

Now I need to take this expression in the "Set variable" action and use it in an IF statement. However I need help with the syntax.

I've tried the following with no success:

@{if(equals(items('For_each_Item_in_Items')?['Exists'], 'ABC'), '1', '2')}
@{if(equals({items('For_each_Item_in_Items')?['Exists']}, 'ABC'), '1', '2')}
@{if(equals(string(items('For_each_Item_in_Items')?['Exists']), 'ABC'), '1', '2')}

Any help or advice would be appreciated.

Azure Logic Apps
Azure Logic Apps

An Azure service that automates the access and use of data across clouds without writing code.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-01-11T12:25:16.837+00:00

    This works:

    @if(equals(string(items('For_each_Item_in_Items')?['Exists']), 'ABC'), '1', '2')
    

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. MayankBargali-MSFT 71,016 Reputation points Moderator
    2022-01-11T12:37:26.07+00:00

    anonymous user Thanks for posting the resolution. Posting for other community members, you can always refer to the workflow definition function reference document. The usage and example for logical comparison function if are covered here.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.