CamlQuery examples SharePoint 2010

Some examples how can use SPquery or caml query in SharePoint 2010 Client Object model.

var site;
var context;
var list;
var collListItem;

context = new SP.ClientContext.get_current();
site = context.get_web();
context.load(site);

list = site.get_lists().getByTitle('MyList');
context.load(list);

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('');
collListItem = list.getItems(camlQuery);
context.load(collListItem);

context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded(sender, args) {

alert("Request succeeded. " + args.Message + "\n" + args.StackTrace);
}

function onQueryFailed(sender, args) {

alert("Request failed. " + args.Message + "\n" + args.StackTrace);

}

0 comments:

Post a Comment

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at sharepointprogrammingblogger@gmail.com .

Copyright (c) 2010 @ myshaepointwork.blogspot.com. All rights are reserved.Do Not Copy.

@ Learning SharePoint.com