How to add Group Headers to an email sent from Logic App in Azure

Azurin4848484 0 Reputation points
2024-03-01T11:52:27.1233333+00:00

I need to send an email from Logic App in Azure
I have a SQL DB recordset to be rendered as a html table to message body, e.g.:

Group1 Name1 Value1
Group1 Name2 Value2
Group1 Name3 Value3
Group2 Name4 Value4

...

I need to render it into smth like this in html table in email:

Group1
Name1 Value1

Name2 Value2

Name3 Value3

Group2

Name4 Value4

how to do it?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,078 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MayankBargali-MSFT 70,126 Reputation points
    2024-03-06T12:42:17.5033333+00:00

    @Azurin4848484 You need to use the above as inline code for the example that Sedat has shared. If you don't want to use the inline query, then you need to use loop to iterate it and build your custom HTML string by using append to variable.

    Alternative you can also offload this functionality to a function app callling it from logic app that would have your custom logic to build the required string as per your business need.

    1 person found this answer helpful.
    0 comments No comments

  2. Sedat SALMAN 13,740 Reputation points
    2024-03-02T12:27:26.1166667+00:00

    assume your SQL query provides data like

    let data = [
        { group: "Group1", name: "Name1", value: "Value1" },
        { group: "Group1", name: "Name2", value: "Value2" },
        { group: "Group1", name: "Name3", value: "Value3" },
        { group: "Group2", name: "Name4", value: "Value4" } 
        // ... more data
    ];
    
    
    

    how you could construct the HTML table

    let htmlTable = "<table>";
    let currentGroup = "";
    
    for (let item of data) {
        if (item.group !== currentGroup) {
            htmlTable += `<tr><th colspan="3">${item.group}</th></tr>`; 
            currentGroup = item.group;
        }
        htmlTable += `<tr><td>${item.name}</td><td>${item.value}</td></tr>`;
    }
    
    htmlTable += "</table>";
    
    // ... (Use the htmlTable variable in your email action)
    
    
    0 comments No comments

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.