Which method is better and why?

I’m populating a DBTreeView and found that both of the following pieces of code seem to function exactly the same. Which is the better (preferred) method to use and why? Is one faster than the other etc.?

//Populate the tree - Method one
var _fs=controller.find();
controller.search(true,true);
_jsTree.addRoots(foundset);

OR

//Populate the tree - Method two
var _fs = databaseManager.getFoundSet(controller.getDataSource());
_fs.loadRecords();
_jsTree.addRoots(_fs);

Thanks,

Keith

The second method is better.

When you go to find mode and do a search without specifying parameters, it does the same query as in your second option, but there will be some overhead. Especially since you use the foundset that is shown on your form, it will do a lot of unnecessary UI stuff when going to find mode and back.

Thank you Joas. What if I needed to add search criteria to the second option? I know in the first I could do something like this:

//Populate the tree - Method one
var _fs=controller.find();
parent_id = '^';
controller.search(true,true);
_jsTree.addRoots(foundset);

But in the second (preffered way) I’m not sure how to add search criteria.

Thanks Again,

Keith

simply do

var _fs = databaseManager.getFoundSet(controller.getDataSource());
if (_fs.find()) {
...
_fs.search();
}