Skip to main content
Level 3
Oct 25, 2020 1:08 PM UTC
Solved

Help - How to sort JavaScript items in an alert Activity

I have a technical workflow that captures fields from the technical workflow and writes them to an alert activity.  The code (below) is working correctly but the output is not sorting by date even through the temporary work table is properly sorted.  Can someone advise the best way to sort the item <%= formatDate(item.CreationDate, "%A %D %B %4Y") %>

 

JS Activity:

var query = xtk.queryDef.create (

<queryDef schema= "temp:query2" operation="select">
<select>
<node expr="CreationDate"/>
<node expr="@appointment"/>
<node expr="Registrations"/>
<node expr="Origin"/>
</select>
</queryDef>)

var itemsXML = query.ExecuteQuery();

vars.itemsXMLString = itemsXML.toXMLString()

 

Alert item: 

<% var itemsXML = new XML(vars.itemsXMLString) for each (var item in itemsXML){ %><% } %>

Creation DateOriginAppointmentRegistrations
<%= formatDate(item.CreationDate, "%A %D %B %4Y") %><%= item.Origin %><%= item.@appointment %><%= item.Registrations %>

 

Current Output:

Creation Date

Origin

Appointment

Registrations

Fri 23 Oct 2020

Blood Type Compatibility Chart

0

32

Sun 18 Oct 2020

Blood Type Compatibility Chart

0

28

Sat 24 Oct 2020

Blood Type Compatibility Chart

0

15

Wed 21 Oct 2020

Blood Type Compatibility Chart

1

1

Mon 19 Oct 2020

Blood Type Compatibility Chart

0

31

Tue 20 Oct 2020

Blood Type Compatibility Chart

0

23

Mon 19 Oct 2020

Blood Type Compatibility Chart

1

1

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
DavidKangni
DavidKangniAccepted solution
Adobe Champion and Community Advisor
Oct 26, 2020 3:13 PM UTC

Hi @wpomeroy ,

 

You should write

 

var query = xtk.queryDef.create (

<queryDef schema= "temp:query2" operation="select">
<select>
<node expr="@appointment"/>
<node expr="Registrations"/>
<node expr="Origin"/>
</select>

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

var itemsXML = query.ExecuteQuery();

vars.itemsXMLString = itemsXML.toXMLString();

 

sortDesc="true" will return descending sort

Thanks,

David

David Kangni

5 replies

Manoj_Kumar
Community Advisor
Community Advisor
Oct 25, 2020 5:25 PM UTC

Hello @wpomeroy ,

 

You can add sortBy in your query def code.

 

sample code

<orderBy> <node expr="@CreationDate" sortDesc="false"/> </orderBy>

 

Let me know if that helps. 

Translate
Manoj  | https://themartech.pro
wpomeroyAuthor
Level 3
Oct 26, 2020 1:30 PM UTC

Hello @_manoj_kumar_, I had tried the before without success.  Below is my updated code.  The data flows through the workflow appropriately but then when i attempt to reference the item in the alert activity (<%= formatDate(item.CreationDate, "%A %D %B %4Y") %>) it  appears blank.  Is there a change that needs to be made in the alert activity?

 

var query = xtk.queryDef.create (

<queryDef schema= "temp:query2" operation="select">
<select>
<orderBy >
<node expr="CreationDate" sortDesc="true"/>
</orderBy >
<node expr="@appointment"/>
<node expr="Registrations"/>
<node expr="Origin"/>
</select>
</queryDef>)

var itemsXML = query.ExecuteQuery();

vars.itemsXMLString = itemsXML.toXMLString()

Translate
DavidKangni
Adobe Champion and Community Advisor
DavidKangniAdobe Champion and Community AdvisorAccepted solution
Adobe Champion and Community Advisor
Oct 26, 2020 3:13 PM UTC

Hi @wpomeroy ,

 

You should write

 

var query = xtk.queryDef.create (

<queryDef schema= "temp:query2" operation="select">
<select>
<node expr="@appointment"/>
<node expr="Registrations"/>
<node expr="Origin"/>
</select>

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

var itemsXML = query.ExecuteQuery();

vars.itemsXMLString = itemsXML.toXMLString();

 

sortDesc="true" will return descending sort

Thanks,

David

Translate
David Kangni
wpomeroyAuthor
Level 3
Oct 26, 2020 7:46 PM UTC

Thanks @DavidKangni. This worked On a related note, do you know how i would go about only pulling a single instance of an item into an alert output? I am using the standard JS conventions below and then referencing them in the alert.  But since i am using 

<% var itemsXML = new XML(vars.itemsXMLString) for each (var item in itemsXML) { %> it is pulling in every single row.  Is there any way for a specific node / item to only pull a single row?  Do i need to define that as a seperate variable?

 

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()

Translate