Is it possible to use GetListItems to perform a query to retrieve a specific item from a sharepoint list using SPServices?

StackOverflow https://stackoverflow.com/questions/13865087

  •  07-12-2021
  •  | 
  •  

Вопрос

I'm wondering if it is possible to use GetListItems to query a list using a specific value and to return only the line(s) that match that query ?

At the moment I can use GetListItems to retrieve all the items in a list, or all the items in a specific view but I can't filter any further.

I appreciate that I can just perform the query on the set of items returned but was wondering if its possible (and perhaps faster) to have sharepoint perform the query for me.

In the yoursharepoint/_vti_bin/Lists.asmx?op=GetListItems page I see,

  <query>
    <xsd:schema>schema</xsd:schema>xml</query>
  <viewFields>
    <xsd:schema>schema</xsd:schema>xml</viewFields>
  <rowLimit>string</rowLimit>
  <queryOptions>
    <xsd:schema>schema</xsd:schema>xml</queryOptions>

But don't know how/if these parameters can be used.

Это было полезно?

Решение

Yes you can call the GetListItems operation and pass the CAMLQuery parameter. Asume the following html

<div id='result'></div>

I'm looking for all listitems matching the term 'Bob Tester' in the title column using the following SPServices call.

$().SPServices({
   operation: "GetListItems",
   async: false,
   listName: "MyCustomList",
   CAMLQuery: "<FieldRef Name='Title'></FieldRef><Value Type='Text'>Bob Tester</Value>",
   CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
   completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
         var foundItem = "<div>" + $(this).attr("ows_Title") + " matches</div>";
         $("#result").append(foundItem);
      });
   }
});

Другие советы

Short answer: yes it is possinle to use it with a variety of filtring

The filtering language (XML) is called CAML..

You should take a look at the SPServices documentstion and forums for tons of examples. The documentation for GetListItems specifically should address your needs on its usage....

This guide will get you started with building a query in CAML: http://sharepointmagazine.net/articles/writing-caml-queries-for-retrieving-list-items-from-a-sharepoint-list

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top