SiteVision Onlinehelp
Search

Extract all files in the file repository order by 'last modified'

Question: How do I extract the last modified file from the file repository?
The following script lists all entries in the file repository ordered by 'last modified'. If you are only interested in the last modified file, simply alter the 'count' parameter in the call to the search method to 1 and use the first SearchHit of the iterator.

var utils = request.getAttribute("sitevision.utils")
var fileRepos = utils.getResourceLocatorUtil().getFileRepository();
var orderByField = new Packages.senselogic.sitevision.api.search.SearchSortField("modified", false);
var orderBy = new ArrayList();
orderBy.add(orderByField);
var query = "path:" + fileRepos.getIdentifier();

var result = utils.getSearchUtil().search(query ,orderBy ,0 , 100);
for (var i = result.getHits(); i.hasNext();)
{
   var hit = i.next();
   var n = hit.getNode();
   out.println(n.getName() + ": "
         + n.getProperty("lastModifiedDate").getDate().getTime()
         + "<br />");
}

Last updated:

se-sto-ste-sv5-2.sitevision-cloud.net
18.222.138.230