CodexBloom - Programming Q&A Platform

Azure Logic Apps: How to Handle Dynamic Content in Email Notifications with Conditional Logic

๐Ÿ‘€ Views: 0 ๐Ÿ’ฌ Answers: 1 ๐Ÿ“… Created: 2025-06-15
azure logic-apps email conditional-logic json

I'm maintaining legacy code that I'm working on an Azure Logic App that sends out email notifications based on certain conditions. My requirement is to personalize the email content dynamically based on user input received from a previous step in the workflow. I want to include different text and attachments based on whether the user has selected 'Option A' or 'Option B'. Currently, I'm using the 'Send an email' action from Office 365 Outlook. However, I need to seem to figure out how to implement the conditional logic to change the email body and attachments depending on the userโ€™s choice. Hereโ€™s a simplified version of my Logic App JSON: ```json { "definition": { "$schema": "https://schema.management.azure.com/schemas/2016-06-01/workflowdefinition.json#", "actions": { "Send_an_email": { "type": "ApiConnection", "inputs": { "host": { "connection": { "name": "office365" } }, "method": "post", "path": "/v2/Mail/SendMail", "body": { "message": { "subject": "Notification", "body": { "contentType": "HTML", "content": "{{if userChoice == 'Option A'}}Content for A{{else}}Content for B{{end}}" }, "to": "user@example.com" } } } } } } } ``` Iโ€™ve tried using an inline code expression to determine the content, but it results in a syntax behavior. The behavior message I receive is "Invalid expression syntax". I also attempted to use the 'Switch' action, but Iโ€™m unsure how to pass the dynamic content to the email action afterwards. How can I effectively implement this conditional logic to personalize the email notifications based on dynamic user input in Azure Logic Apps? My development environment is Ubuntu 22.04. Is this even possible?