HTML Template in expression rule

Certified Senior Developer

Hi Community,

i have a requirement to create a html template using expression rule to create a table.

i am able to create a table but i am unable to generate borders for each row and headers. please prefer below code snippet.

TIA

 

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Senior Developer
    in reply to Harsha Sharma

    Hi Harsha,

    Thanks for your response can you please do it in below code snippet i am getting error while doing the same.

    It will be very helpful for me.

    a!localVariables(
    
      local!dataDict:{
        {
          name:"ABCD",
          age:25,
          company:"AS"
        },
        {
          name:"QWER",
          age:27,
          company:"AT"
        },
        {
          name:"SDFG",
          age:28,
          company:"Ay"
        }
      },  
      local!columns:{
        { column: "name", width: 10},
        { column: "age", width: 20},
        { column: "company", width: 40}
      },
      "<table style=""width:100%; border:1px solid black;border-collapse:collapse"">
    <tr>" & joinarray(
      a!forEach(
        local!columns,
        "<th style=""width:" & fv!item.width & "%"">" & fv!item.column & "</th>"
      ),
      ""
    ) & "</tr>" & joinarray(
      a!forEach(
        items: local!dataDict,
        expression: 
        "<tr>
    <td>" & fv!item.name & "</td>
    <td>" & fv!item.age & "</td>
    <td>" & fv!item.company & "</td>
    
    </tr>"
      ),
      ""
    )&"</table>"
    )

  • 0
    Certified Lead Developer
    in reply to kirang100133

    What kind of error do you get?

  • +1
    Certified Lead Developer
    in reply to kirang100133

    You can try the below

    a!localVariables(
    
      local!dataDict:{
        {
          name:"ABCD",
          age:25,
          company:"AS"
        },
        {
          name:"QWER",
          age:27,
          company:"AT"
        },
        {
          name:"SDFG",
          age:28,
          company:"Ay"
        }
      },  
      local!columns:{
        { column: "name", width: 10},
        { column: "age", width: 20},
        { column: "company", width: 40}
      },
      "<table style=""width:100%; border:1px solid black;border-collapse:collapse"">
    <tr>" & joinarray(
      a!forEach(
        local!columns,
        "<th style=""width:" & fv!item.width & "%;border-bottom:1pt solid black"">" & fv!item.column & "</th>"
      ),
      ""
    ) & "</tr>" & joinarray(
      a!forEach(
        items: local!dataDict,
        expression: 
        "<tr style=""border-bottom:1pt solid black"">
    <td>" & fv!item.name & "</td>
    <td>" & fv!item.age & "</td>
    <td>" & fv!item.company & "</td>
    
    </tr>"
      ),
      ""
    )&"</table>"
    )