Share via

In Logic Apps Adding condition as action or use if/contains function while assigning a variable, which should be batter

Bharvi Bhut 181 Reputation points
Mar 13, 2023, 10:30 AM
    • I have created an playbook which triggers on incident.
      I want one string variable which has all custom alert details separated by comma (for example: var x = "custom filed 1 , custom filed 2")
  • For this first I have to check that custom fields is exist or not, and if exists then append it to my string variable.
  • I am having 25 custom alert fields, so currently I applies the condition action and in true part I am appending the value of string. Is it a proper way or any proper way is there? User's image
Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,300 questions
{count} votes

Accepted answer
  1. MayankBargali-MSFT 70,786 Reputation points
    Mar 14, 2023, 5:52 AM

    @Bharvi Bhut Thanks for reaching out. As you are using multiple condition so for every action you will be billed so to check one value you are using two actions so it would be 50+ actions just to check and assign the value. As there are many actions so it would be not decipherable. The workaround would be defining this condition check during the assigning the value to your variable or offload this functionality to inline code.

    For example, I have defined assign the Tag variable with my custom value based on the input on my Parse_JSON action.

    You can see I have used concat to combine the string and inside it I am comparing my input to some value and then it will add it to my main string variable.

    User's image

    concat(
      if(
        contains(toLower(body('Parse_JSON')?['tag'][0]),'cu1'),
        'CustomValue1',
        ''
      ),
      if(contains(toLower(body('Parse_JSON')?['tag'][0]),'cu2'),
        'CustomValue2',
        ''
      ),
      if(contains(toLower(body('Parse_JSON')?['tag'][0]),'cu3'),
        'CustomValue3',
        ''
      ),
      if(contains(toLower(body('Parse_JSON')?['tag'][0]),'cu4'),
        'CustomValue4',
        ''
      )
    )
    
    

    The above is just for reference and you need to change according to the condition that you have define and different function expression that you are leveraging. If you are choosing the above method, then in consumption logic app it would be only one action that would be billed for you. For standard logic app all the build-in conectors are free but not the azure connectors.

    Hope the above and feel free to get back to me if you need any assistance.

    Please accept as "Yes" if the answer is helpful so that it can help others in the community. If you need any help/clarification/concerns/follow up questions, then please click on "Add Comment" on my answer and provide more details.


0 additional answers

Sort by: Most helpful

Your answer

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