Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Help - How to sort JavaScript items in an alert Activity

Avatar

Avatar
Validate 1
Level 1
wpomeroy
Level 1

Likes

0 likes

Total Posts

17 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
wpomeroy
Level 1

Likes

0 likes

Total Posts

17 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
wpomeroy
Level 1

25-10-2020

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

alert javascript

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
DavidKangni
MVP

Likes

246 likes

Total Posts

358 posts

Correct Reply

142 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Validate 1
MVP
DavidKangni
MVP

Likes

246 likes

Total Posts

358 posts

Correct Reply

142 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
DavidKangni
MVP

26-10-2020

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

wpomeroy

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

DavidKangni

Hi @wpomeroy,

 

Not sure I completely understood your question, but you can add a where clause or a group by clause to get an aggregate or a single row. You can also add a lineCount to your query def to get the number of row you want.

 

Hope that helps.

Thanks,

David 

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
MVP
_Manoj_Kumar
MVP

Likes

102 likes

Total Posts

300 posts

Correct Reply

96 solutions
Top badges earned
Validate 1
Contributor
Ignite 1
Shape 1
Give Back 5
View profile

Avatar
Validate 1
MVP
_Manoj_Kumar
MVP

Likes

102 likes

Total Posts

300 posts

Correct Reply

96 solutions
Top badges earned
Validate 1
Contributor
Ignite 1
Shape 1
Give Back 5
View profile
_Manoj_Kumar
MVP

25-10-2020

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.