Export (0) Print
Expand All

SP.List.getItems(query_) Method

SharePoint 2010

Last modified: June 25, 2010

Applies to: SharePoint Foundation 2010

In this article
Return Value
Remarks
Applies To

Returns a collection of items from the list based on the specified query.

var value = SP.List.getItems(query_);

query_

A SP.CamlQuery Class object that contains the query.

Type: SP.CamlQuery

SPException

The field specified in the query is not present in the list. Error code: -2130575340.

SPQueryThrottledException

The throttling limit is exceeded by the operation. Error code: -2147024860.Or there is a lack of resources available to process the request. Error code: -2147024749.

UnauthorizedAccessException

The user has insufficient permissions to perform the operation. Error code: -2147024891.

It must not be null.

The following example creates an input button on an application page that gets announcements in the current web site that contain the text announce.

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<script type="text/ecmascript" language="ecmascript">

var listItems;

function runCode() {
  var clientContext = new SP.ClientContext();
  var targetList = clientContext.get_web().get_lists().getByTitle('Announcements');
  var query = new SP.CamlQuery();
  query.set_viewXml("<View><Query><Where><Contains><FieldRef Name='Title'/><Value Type='Text'>announce</Value></Contains></Where></Query></View>");
  listItems = targetList.getItems(query);
  clientContext.load(listItems);
  clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {
  var listEnumerator = listItems.getEnumerator();
  while (listEnumerator.moveNext()) {
    alert("Item containing ‘announce’ found! \nTitle: " + listEnumerator.get_current().get_item("Title"));
  }  
}

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

</script>

    <input id="Button1" type="button" value="Run Code" onclick="runCode()" />

</asp:Content>
Show:
© 2014 Microsoft