Expand my Community achievements bar.

SOLVED

Send Email with dynamic table

Avatar

Community Advisor

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> 

      }
  

%>

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

6 Replies

Avatar

Community Advisor

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

Avatar

Correct answer by
Community Advisor

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

Avatar

Administrator

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

Avatar

Community Advisor

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

1982luca_0-1647245865628.png

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

1982luca_1-1647246514531.png

any idea?

 

Avatar

Administrator

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



Sukrity Wadhwa

Avatar

Community Advisor

hi luca,

 

There is an error in your script attachDispName. Plus I think it may not be a good idea to query the whole deliveries table. 

I have a similar workflow that is sending a daily report of deliveries

 

DavidKangni_0-1647281012663.png

 

 

DavidKangni_1-1647281106095.png

 



David Kangni