Search code examples
sharepointsharepoint-onlinesharepointframework

SharePoint Online SP.CamlQuery is undefined


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


Solution

  • 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
    });