SP.ClientContext.loadQuery method (sp.js)

Retrieves an enumerable sequence of child client objects from the specified collection.

Applies to: apps for SharePoint | SharePoint Foundation 2013 | SharePoint Server 2013

SP.ClientContext.loadQuery(clientObjectCollection, exp)

Parameters

  • clientObjectCollection
    SP.ClientObjectCollection
    The specified collection.

  • exp
    String
    An optional expression string to filter the results.

Return value

ArrayList

Remarks

The loadQuery method is inherited from the SP.ClientRuntimeContext object.

Example

The following code example shows how to use the loadQuery method with an "Include" expression string.

function retrieveSpecificListPropertiesToCollection(siteUrl) {
    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    var collList = oWebsite.get_lists();

    this.listInfoCollection = clientContext.loadQuery(collList, 'Include(Title, Id)');
    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded), 
        Function.createDelegate(this, this.onQueryFailed)
    );
}

function onQuerySucceeded() {
    var listInfo = '';

    for (var i = 0; i < this.listInfoCollection.length; i++) {
        var oList = this.listInfoCollection[i];
        listInfo += 'Title: ' + oList.get_title() + 
            ' ID: ' + oList.get_id().toString();
    }
    alert(listInfo.toString());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + 
        '\n' + args.get_stackTrace());
}

See also

Other resources

SP.ClientContext

Complete basic operations using JavaScript library code in SharePoint 2013