Monday, December 9, 2013

How to use CAML Query in Client Object Model


Most of us may face this issue in their application while using CAML in COM. That is,

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<Query><Where><BeginsWith><FieldRef Name='Name'/><Value Type='Text'>asdf</Value></BeginsWith></Where></Query>");
                this.listItemCollection = oList.getItems(camlQuery);
                context.load(listItemCollection);

The above mentioned code may not give you the result. Replace CAML query like this,

var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<query><Query><Where><BeginsWith><FieldRef Name='Name'/><Value Type='Text'>asdf</Value></BeginsWith></Where></Query></query>");
                this.listItemCollection = oList.getItems(camlQuery);
                context.load(listItemCollection);

Enjoy Coding !!!! :) 

No comments:

Post a Comment