Search code examples
emailsendgridresultsetazure-logic-apps

Using Logic Apps, how can I input a formatted Table of results from an SQL Stored Procedure into SendGrid Email


Once a day, I need to run an SQL Stored Procedure, which collects a list of results. I then need to input the results, as a nice user friendly table, into an e-mail (SendGrid).

So far, I have setup all connections and got the Logic App to work but the e-mail it generates displays the results like this:

{"Table1":[{"CaseID":"1000001","DateOfUdate":"2020-06-09T11:34:57.483"},{"CaseID":"1000002","DateOfUdate":"2020-06-09T11:34:57.483"},{"CaseID":"1000003","DateOfUdate":"2020-06-09T11:34:57.483"},{"CaseID":"1000004","DateOfUdate":"2020-06-09T11:34:57.483"}]}

How can I get this to be displayed as a proper table?

Case ID    DateofUpdate
1000001    2020-06-09T11:34:57.483
1000002    2020-06-09T11:34:57.483
1000003    2020-06-09T11:34:57.483
1000004    2020-06-09T11:34:57.483

Below are images of my Logic App - please let me know if I need to provide more information.

Schedule

Stored Procedure

SendGrid Email


Solution

  • For this requirement, please refer to the steps I provided below:

    1. I initialize a variable named "resultSetVar" and store the json data same to yours', use this variable to simulate your "ResultSets" data. enter image description here

    2. Then use "Parse JSON" action to parse the json data. enter image description here

    3. After that, use "Create HTML table" action to create the html with the json array "Table1" from the "Parse JSON" action. enter image description here

    4. At last, put the "Output" from "Create HTML table" action into the "Email body" box. enter image description here

    5. Running the logic app, I received the email shown as below

    enter image description here

    Hope it helps~