1

I am trying to retrieve items from a Sharepoint 2013 list using JSOM with CAML query.

camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">Hai</Value></Eq></Where></Query></View>');
 this.collListItem = oList.getItems(camlQuery);
clientContext.load(collListItem);

Exactly at After clientContext.load I am getting an exception like below:

Uncaught Error: Sys.ArgumentNullException: Value cannot be null. Parameter name: clientObject at Function.Error$create [as create] (ScriptResource.axd?d=z-TpJGMxry662OihfqljDL26fiN46CFgw-dc63w_0oeRlpp6N9gJsaBwPeMFyqrxHJ8pqpl9ZXTIDm…:237) at Function.Error$argumentNull [as argumentNull] (ScriptResource.axd?d=z-TpJGMxry662OihfqljDL26fiN46CFgw-dc63w_0oeRlpp6N9gJsaBwPeMFyqrxHJ8pqpl9ZXTIDm…:279) at SP_ClientContext.SP_ClientRuntimeContext$load [as load] (VM2726 sp.runtime.debug.js?rev=VFkBZgkYpbAZS6abSrBqIg%3D%3D:3261) at Publish (AllNewsFeed.aspx:1113) at HTMLInputElement.onclick (XYZ.aspx:2109)

2

Looks like you have used the MSDN sample.

Try it as below:

var listItemCollection = null;   

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', queryListItems);

function queryListItems() {  
     var context = new SP.ClientContext();        
     var list = context.get_web().get_lists().getByTitle('CustomList'); //change as per your list name        
     var caml = new SP.CamlQuery();        
     caml.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">Hai</Value></Eq></Where></Query></View>');
     listItemCollection = list.getItems(caml);  
     context.load(listItemCollection);        
     context.executeQueryAsync(onSucceededCallback, onFailedCallback);  
}  


function onSucceededCallback(sender, args) {  
     var enumerator = listItemCollection.getEnumerator();  
     while (enumerator.moveNext()) 
     {  
        var listItem = enumerator.get_current();  
        console.log(listItem.get_item('Title'));         
     }      
}  

function onFailedCallback(sender, args) {  
    console.log('Message: ' + args.get_message());        
} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.