skip to Main Content

i am creating an Azure logic app workflow. as a part of it, i have an array and i need to create a table, for each item in the array i need to have one row in the table. and finally send that table via email. i have tried the inline java script action with the below code. but i get error InlineCodeScriptRuntimeFailure. The inline code action 'JavaScriptCode' execution failed, with error 'document is not defined'. anyone knows how i can fix it? or is there any other way to do that?

var rows = [{
    name: "John",
    age: 20,
    email: "[email protected]"
}, {
    name: "Jack",
    age: 50,
    email: "[email protected]"
}, {
    name: "Son",
    age: 45,
    email: "[email protected]"
}];

var html = "<table border='1|1'>";
for (var i = 0; i < rows.length; i++) {
    html+="<tr>";
    html+="<td>"+rows[i].name+"</td>";
    html+="<td>"+rows[i].age+"</td>";
    html+="<td>"+rows[i].email+"</td>";
    
    html+="</tr>";

}
html+="</table>";
document.getElementById("box").innerHTML = html;

2

Answers


  1. Code is true. Do you work with any frameworks?

    Login or Signup to reply.
  2. i have an array and i need to create a table, for each item in the array i need to have one row in the table. and finally send that table via email.

    To achieve this follow below design:

    enter image description here

    Inline code modified at end a bit:

    var rows = [{
        name: "John",
        age: 20,
        email: "[email protected]"
    }, {
        name: "Jack",
        age: 50,
        email: "[email protected]"
    }, {
        name: "Son",
        age: 45,
        email: "[email protected]"
    }];
    
    var html = "<table border='2|2'>";
    for (var i = 0; i < rows.length; i++) {
        html+="<tr>";
        html+="<td>"+rows[i].name+"</td>";
        html+="<td>"+rows[i].age+"</td>";
        html+="<td>"+rows[i].email+"</td>";
        
        html+="</tr>";
    
    }
    html+="</table>";
    return html;
    

    Compose Action:

    <style>
    #testID table, table th, table td {border: 1px solid #0000FF}
    </style>
    <div id="testID">
    @{body('Execute_JavaScript_Code')}
    </div>
    

    Output:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search