Send Email with dynamic table | Community
Skip to main content
Luca_Lattarini
Level 9
February 16, 2022
Solved

Send Email with dynamic table

  • February 16, 2022
  • 3 replies
  • 1967 views

Hello guys,

I am trying to send an email with dynamic row by using the code below but I am getting the error xtk not defined. Do you know which library shall i  use? Any suggestion?

Thanks

Luca

 

<%

       
      var query = xtk.queryDef.create(
      <queryDef schema="ssg:purchase" operation="select"  distinct="true">
      <select>
      <node expr="@code"/>
      <node expr="@desc"/>
      
      </select>
      </queryDef>
      );
      
      var resultSet = query.ExecuteQuery();
    var res = new XML(resultSet);

    
  
    var line = 1;
    
    for each (var row in res) { 
             
     <dynamic row table> 

      }
  

%>

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by DavidKangni

try this 

 

<TABLE>
  <TBODY>
  <TR>
    <TH align=left>Code</TH>
    <TH>Description</TH></TR><%

var query = xtk.queryDef.create(
      <queryDef schema="ssg:purchase" operation="select" distinct="true">
        <select>  
          <node expr="@code" alias="code"/>  
          <node expr="@desc" alias="desc"/> 
        </select> 
      </queryDef>
    ).ExecuteQuery();
    for each (var record in query )
    {
      vars.code=record.code;
      vars.desc=record.desc;
%> 
  <TR>
    <TD><%= vars.code %></TD>
    <TD><%= vars.desc %></TD></TR><%
}
%> </TBODY></TABLE>

Thanks,

David

3 replies

Amine_Abedour
Community Advisor
Community Advisor
February 16, 2022

Hello @luca_lattarini,

 

You can not use querydef in your email. However you can achieve what you are trying to do by using the same method explained here.

 

Br

 

Amine

Amine ABEDOUR
DavidKangni
Community Advisor
DavidKangniCommunity AdvisorAccepted solution
Community Advisor
February 16, 2022

try this 

 

<TABLE>
  <TBODY>
  <TR>
    <TH align=left>Code</TH>
    <TH>Description</TH></TR><%

var query = xtk.queryDef.create(
      <queryDef schema="ssg:purchase" operation="select" distinct="true">
        <select>  
          <node expr="@code" alias="code"/>  
          <node expr="@desc" alias="desc"/> 
        </select> 
      </queryDef>
    ).ExecuteQuery();
    for each (var record in query )
    {
      vars.code=record.code;
      vars.desc=record.desc;
%> 
  <TR>
    <TD><%= vars.code %></TD>
    <TD><%= vars.desc %></TD></TR><%
}
%> </TBODY></TABLE>

Thanks,

David

David Kangni
Sukrity_Wadhwa
Community Manager
Community Manager
March 3, 2022

Hi @luca_lattarini,

Were you able to resolve this query with the help of any of the given solutions or do you still need more help here? Do let us know.
Thanks!

Sukrity Wadhwa
Luca_Lattarini
Level 9
March 14, 2022

Hello Sukrity_Wadhwa,

No I still have issue. By Considering that I want to send out a summery delivery table with Open, clicks etc,  I created a simple workflow as showed below

The JS code has the query 

 

var eQuery = xtk.queryDef.create(
<queryDef schema="nms:delivery" operation="select">
<select>
<node expr="@id"/>
<node expr="@internalName"/>
<node expr="@label"/>
<node expr="@state"/>
<node expr="@lastModified"/>
<node expr="[scheduling/@contactDate]"/>
<node expr="[scheduling/@validityDate]"/>
<node expr="[properties/@toDeliver]"/>
<node alias="@_progression" expr="Percent([indicators/@processed], [properties/@toDeliver])"/>
<node expr="[indicators/@successRatio]"/>
<node alias="@dataQuality" expr="Percent([indicators/@unknownUser], [indicators/@processed]) + Percent([indicators/@mailboxFull], [indicators/@processed]) + Percent([indicators/@invalidDomain], [indicators/@processed])"/>
<node alias="@reputation" expr="Percent([indicators/@refused], [indicators/@processed]) + Percent([indicators/@unreachable], [indicators/@processed])"/>
<node alias="@optOut" expr="[indicators/@optOut]"/>
<node alias="@optOutRatio" expr="[indicators/@optOutRatio]"/>
<node alias="@opens" expr="[indicators/@totalRecipientOpen]"/>
<node alias="@clickRatio" expr="[indicators/@recipientClickRatio]"/>
<node alias="@clicks" expr="[indicators/@recipientClick]"/>
<node alias="@errors" expr="[indicators/@error]"/>
<node alias="@errorRatio" expr="[indicators/@errorRatio]"/>
</select>


</queryDef>).ExecuteQuery();


instance.vars.deliveries=eQuery; // assign query result to instance.vars.deliveries;

in the Alert I have the code below

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" ""><HTML><HEAD>
</HEAD>
<BODY><%


var deliveries = new XML(instance.vars.deliveries);

 


for each (var delivery in deliveries )
{
vars.code=delivery.@label;

%><%


}
%>
<TABLE>
<TBODY>
<TR>
<TH align="left">Code</TH>
</TR>
<TR>

<TD><%= vars.code %></TD></TR></TBODY></TABLE></BODY></HTML>

 

if I try to run the workflow I have the error below

any idea?

 

Sukrity_Wadhwa
Community Manager
Community Manager
March 14, 2022

Thanks @luca_lattarini for sharing this. I will escalate your issue among our SMEs.

Sukrity Wadhwa