I have a scenario where multiple variables will be passed from ADF to logic apps. The variables hold JSON content and it needs to be converted to tables and added to mail content.
Could someone explain how I can receive variables from logic app, transform each variable to HTML table and add it to mail content.
I have reproduced in my environment and below are my expected results:
NOTE:
Variable inputs need to be in JSON and then should be transformed into JSON array as Create HTML Table
action in Logic apps takes only JSON array as an input.
Example Input:
[{"id": 8,"name": "Rithwik","email": "[email protected]"},{"product": "lappy","price": 10,"quantity": 1},{"title": "Task","description": "Some Task","status": "Working"}]
Here I have taken three different table inputs.
Design:
Then in For Each:
Then send an email:
Output:
Codeview:
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_each": {
"actions": {
"Append_to_string_variable": {
"inputs": {
"name": "var2",
"value": "<style>\n#testID table, table th, table td {border: 1px solid #0000FF}\n</style>\n<div id=\"testID\">\n@{body('Create_HTML_table')}\n</div>\n\n***********************************************************************************\n"
},
"runAfter": {
"Create_HTML_table": [
"Succeeded"
]
},
"type": "AppendToStringVariable"
},
"Create_HTML_table": {
"inputs": {
"format": "HTML",
"from": [
"@items('For_each')"
]
},
"runAfter": {},
"type": "Table"
}
},
"foreach": "@variables('var1')",
"runAfter": {
"Initialize_variable_2": [
"Succeeded"
]
},
"type": "Foreach"
},
"Initialize_variable": {
"inputs": {
"variables": [
{
"name": "var1",
"type": "array",
"value": [
{
"email": "[email protected]",
"id": 8,
"name": "Rithwik"
},
{
"price": 10,
"product": "lappy",
"quantity": 1
},
{
"description": "Some Task",
"status": "Working",
"title": "Task"
}
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_variable_2": {
"inputs": {
"variables": [
{
"name": "var2",
"type": "string"
}
]
},
"runAfter": {
"Initialize_variable": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Send_an_email_(V2)": {
"inputs": {
"body": {
"Body": "<p>@{variables('var2')}</p>",
"Importance": "Normal",
"Subject": "IMPORTANT",
"To": "[email protected]"
},
"host": {
"connection": {
"name": "@parameters('$connections')['office365']['connectionId']"
}
},
"method": "post",
"path": "/v2/Mail"
},
"runAfter": {
"For_each": [
"Succeeded"
]
},
"type": "ApiConnection"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {
"$connections": {
"defaultValue": {},
"type": "Object"
}
},
"triggers": {
"manual": {
"inputs": {
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {
"$connections": {
"value": {
"office365": {
"connectionId": "/subscriptions/b83c1ed3/resourceGroups/v-rbojja/providers/Microsoft.Web/connections/office365",
"connectionName": "office365",
"id": "/subscriptions/b83c1ed3/providers/Microsoft.Web/locations/eastus/managedApis/office365"
}
}
}
}
}