Search code examples
sharepointsharepoint-2010sharepoint-jsom

JSOM - Load mutliple SharePoint objects in one request


Is there a way to load multiple objects in one request like this:

var context = new SP.ClientContext.get_current();
                    this.web = context.get_web();
                    this.site = context.get_site();
                    var list = this.web.get_lists().getByTitle(window.sessionStorage.getItem('selectedContentType'));
                    var query = '<View Scope=\'RecursiveAll\'><Query>' + $('.camlQuery').val() + '</Query></View>';
                    var camlQuery = new SP.CamlQuery();
                    camlQuery.set_viewXml(query);
                    this.items = list.getItems(camlQuery);
                    context.load(this.site);
                    context.load(this.items, 'Include(ID,DocIcon,LinkFilename,FileRef,FileLeafRef,Title,ContentType,SupplierPGProduct)');
                    context.executeQueryAsync(Function.createDelegate(this, get_Data_onSuccess), Function.createDelegate(this, get_Data_onFailure));
                }

In this example, I mean this.site and this.items in one async request? Or do I have to load first this.site and when the request is successful, then load the this.items?


Solution

  • I've found the answer in sharepoint.stackexchange. Here is the link to the answer.

    https://sharepoint.stackexchange.com/a/227984/47825