Valery Yegorov
Valery Yegorov

Reputation: 191

SharePoint Online SP.CamlQuery is undefined

I'm implementing SharePoint Online Add-in I need SP.CamlQuery.createAllItemsQuery() data, but SP.CamlQuery is undefined

Upvotes: 0

Views: 513

Answers (1)

tinamou
tinamou

Reputation: 2291

SP.CamlQuery is defined in sp.js but your code runs when sp.js is not loaded. So to overcome this use SP.SOD.executeFunc to delay execution of your code until sp.js loads.

Note: both have SP namespace but SP.SOD.executeFunc is defined in core.js file and is always loaded in SharePoint.

Code:

SP.SOD.executeFunc('sp.js', SP.ClientContext, function() {
    // do stuff, use SP.CamlQuery object
});

Upvotes: 1

Related Questions