I have a list view set up via the webinterface of Sharepoint. Now I want to use this view (the CAML XML) to be loaded into javscript to provide list items for a Content Editor Webpart. The view works as intended on the Sharepoint website. But when I load the view via JavaScript my defined filters:
- Sort in descending order after Date of Creation
- Limit the displayed list items to 3 Items
don't work. The items returned from the AsyncQuery are all list items and are not ordered as specified.
Can anybody help me?
My Code:
getItemsFromView: function (listTitle, viewTitle, context)
{
var list = context.get_web().get_lists().getByTitle(listTitle);
var view = list.get_views().getByTitle(viewTitle);
var query = new SP.CamlQuery();
context.load(view);
context.load(list);
context.executeQueryAsync(
function(sender,args) { query.set_viewXml("<View><Query>" + view.get_viewQuery() + "</Query><RowLimit>3</RowLimit></View>");},
function(sender,args) {alert('Getting news failed. ' + args.get_message() + '\n' + args.get_stackTrace())}
);
var items = list.getItems(query);
context.load(items);
context.executeQueryAsync(Function.createDelegate(this, function(){this.onQuerySucceeded(items)}), Function.createDelegate(this, this.onQueryFailed));
},