This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Nov 26, 2013, 5:05 PM
13 Posts

Sort computed field data from mulitple databases

  • Category: Server Side JavaScript
  • Platform: Windows
  • Release: 9.0.1
  • Role: Developer
  • Tags:
  • Replies: 4

On my XPage, I have a computed field.  This field has code to pull in information from other databases, so I want to display the date and subject.  In the view in the database, I string together the date and subject in one column.  This is the column I pull the data from, ex) 11/25/13  Thanksgiving Holiday.  I get the information to display in the computed field, but I want to sort the data by date in descending order.  Any ideas how to accomplish this?

 

var dbName = new Array("s1","SO1.nsf");

var customers2 = @DbColumn(dbName,"notices",10);

var SecSenateList = "";

for(var z=0;z<customers2.length;z++) {

SecSenateList = SecSenateList + customers2[z];

}

 

var dbName = new Array("s1","SO2.nsf");

var customers = @DbLookup(dbName,"allnews","Yes",6);

for(var i=0;i<customers.length;i++) {

SecSenateList = SecSenateList + customers[i];

}

return SecSenateList;

Nov 26, 2013, 6:23 PM
298 Posts
Use a Java TreeMap
A TreeMap will automatically sort the members based on the key (which you would use the Date, or String representation of the date) and then you can use that in your computed field or better yet, a repeat control and put the computed field in it.  See http://www.intec.co.uk/mapping-java-collections/

Howard
Nov 27, 2013, 3:28 PM
47 Posts
using just @Sort()

I've not tried this.. and I know that @DbColumn may NOT return an array but from a Formula language perspective this may work.  Not sure if you have to check for error on @DbLookup either.  There is a [FAILSILENT] option in formula language.

var customers = @Sort(@DbColumn(new Array("s1","SO1.nsf"),"notices",10):@DbLookup(new Array("s1","SO2.nsf"),"allnews","Yes",6));

Nov 27, 2013, 5:29 PM
453 Posts
Think the treeMap is the solution

My understanding is that the @DBColumn and @DBLookup are not very efficient. I had a situation where I was getting a returned document collection from a FTIndex search but then needed to sort it into a sequence that was fed into a repeat control. As the result of the search could be several hundred documents I found the using other methods very cumbersome and slow. I changed it to using the treeMap and the result was a quick clean solution. 

I have used the treeMap in several different situations where what I wanted was a unique sorted list of values.

Here is a link to how this ended up:

http://www-10.lotus.com/ldd/xpagesforum.nsf/xpTopicThread.xsp?documentId=43F21C163B41891A85257BE800728E66#247FE3C55D48015B85257BE9006C2BD9

Apr 1, 2015, 7:16 PM
13 Posts
sort table by date

I got the TreeMap to work and it does a great job sorting by date.  However, I cannot use this method because it omits duplicates.  So, if I have two dates that are the same, it only uses one entry with that date and doesn't display the other.  Any other ideas how I can get a table to sort in xpages by date?


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal