Expand my Community achievements bar.

SOLVED

Help - Define a variable from the temp: table and call in an alert activity

Avatar

Level 3

I am trying to define a variable (or query def) in a JS alert and then call the variable or item in an alert activity.  I am aware of the current stock method using:

 

<% var itemsXML = new XML(vars.itemsXMLString)

for each (var item in itemsXML){

%>

 

However, i don't want to call every instance of the particular field / node.  I have some fields i want to output into a table and some where i only want a single instance of the field.  Below is my current setup:

 

JS Activity -- For the nodes "Web Registations" and "Appt Sum" i only want to include the first row.  For all the other nodes i want to include every occurence.

 

var query = xtk.queryDef.create (

<queryDef schema= "temp:union" operation="select">
<select>
<node expr="CreationDate" />
<node expr="@appointment"/>
<node expr="Registrations"/>
<node expr="Origin"/>
<node expr="WebRegistrations"/>
<node expr="ApptSum"/>
</select>

<orderBy >
<node expr="CreationDate" sortDesc="true"/>
</orderBy >
</queryDef>)

var itemsXML = query.ExecuteQuery();

vars.itemsXMLString = itemsXML.toXMLString()
instance.vars.WebRegistrations=[INSERT WF FIELD HERE]

 

ALERT ACTIVITY


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<STYLE>
table {
border-collapse: separate;
border-spacing: 0;
color: #4a4a4d;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
}
th,
.title {
border-spacing: 0;
color: #4a4a4d;
font: 14px/1.4 "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: bold;
}
}
td {
padding: 10px 15px;
vertical-align: left;
}
thead {
background: #808080;
color: #fff;
}
th:first-child {
text-align: left;
}
tbody tr:nth-child(even) {
background: #f0f0f2;
}
td {
border-bottom: 1px solid #cecfd5;
border-right: 1px solid #cecfd5;
border-top: 1px solid #cecfd5;
border-left: 1px solid #cecfd5;
}
td:first-child {
border-left: 1px solid #cecfd5;
}
tfoot {
text-align: right;
}
tfoot tr:last-child {
background: #f0f0f2;
}
</STYLE>

<META name=GENERATOR content="MSHTML 11.00.10570.1001"></HEAD>
<BODY>
<P><STRONG>Daily Campaign/Delivery Details&nbsp;for <%= formatDate(new Date(), "%2M/%2D/%2Y") %></STRONG>
<DIV class=Title>
<P># of campaigns: <%= instance.vars.WebRegistrations %></P></DIV><BR>
<TABLE id=t02>
<TBODY>
<THEAD>
<TR>
<TD>Creation Date</TD>
<TD>Origin</TD>
<TD>Appointment</TD>
<TD>Registrations</TD>
</TR></THEAD><%

var itemsXML = new XML(vars.itemsXMLString)

for each (var item in itemsXML){

%>
<TBODY>
<TR>
<TD><%= formatDate(item.CreationDate, "%A %D %B %4Y") %></TD>
<TD><%= item.Origin %></TD>
<TD><%= item.@appointment %></TD>
<TD><%= item.Registrations %></TD></TR></TBODY><%

} %> </TBODY></TABLE><BR><BR>
<P></P></BODY></HTML>

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @wpomeroy,

 

You must change the operation type to "get" or "getIfExists" instead of "select".

A get operation returns the first data element in the query (if there is one), or an exception if there is nothing the result-set.

A getIfExists operation returns the first data element in the query (if there is one), or an empty element if there is nothing the result-set.

Use these operations when you know that all records in your target schema have the same value for that field (the one you want to select from that schema).

 

Let me know if that is what you needed.

 

Regards,

Ishan

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @wpomeroy,

 

You must change the operation type to "get" or "getIfExists" instead of "select".

A get operation returns the first data element in the query (if there is one), or an exception if there is nothing the result-set.

A getIfExists operation returns the first data element in the query (if there is one), or an empty element if there is nothing the result-set.

Use these operations when you know that all records in your target schema have the same value for that field (the one you want to select from that schema).

 

Let me know if that is what you needed.

 

Regards,

Ishan

Avatar

Administrator

Hi @wpomeroy

Were you able to resolve this query with the given solution or do you still need more help? Do let us know.

Thanks!



Sukrity Wadhwa