CAML Query in GetListItems

Aug 9, 2010 at 6:07 PM
Edited Aug 9, 2010 at 6:43 PM

Can anyone spot my rookie error?

I was just getting started with the GetListItems and now I needed to use the CAML query part.....

Unfortunately whatever I seem to type in here it stops working :-(

This works without the CAMLQuery line but not with it (I have tried variations of Contains and with / without the <Query> element, all to no avail ) :

$().SPServices({
    operation: "GetListItems",
    async: false,
    webURL: "http://server/parentsite",
    listName: "x_Departments",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    CAMLQuery: "<Query><Eq><FieldRef Name='Title'/><Value Type='Text'>Test</Value></Eq></Query>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName=z:row]").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });

Do I need the CAMLQueryOptions?, what form would that take?

Aug 9, 2010 at 10:46 PM

Rookie?  I still forget the syntax every now and again. : )

You need to include both the Query and Where tags . . .

CAMLQuery: "<Query><Where><Eq><FieldRef Name='Title'/><Value Type='Text'>Test</Value></Eq></Where></Query>",
Aug 10, 2010 at 5:07 PM

Great!

Thank you so much for your speedy reply...

Oct 15, 2010 at 2:35 PM

Does this <Query><Where> syntax need to be used in the SPCascadedropDowns too?

If so the CAMLquesry snippet on the document pages  could do with updating....

(and thanks for all the great stuff here!)

Oct 15, 2010 at 11:33 PM

I have successfully used a CAMLQuery in an SPCascadeDropDown and SPDisplayRelatedInfo with only a <Contains> tag surrounding it.  And yes, the documentation is not exact but much more thorough than other projects.  I'm sure if you submitted a request he would update the docs.

Coordinator
Oct 18, 2010 at 1:30 AM

Ruth and Toad:

The reason that the CAMLQuery in SPCascadeDropdowns and SPDisplayRelatedInfo can (and should be) be a simple fragment is that it's combined with the other parts of the queries which are required to make the functions do their thing. In both functions, I'm filtering based on the values in the dropdowns and adding the CAMLQuery into that logic if it is provided.

Make sense?

I'll try to update the docs to make that a little clearer.

M.

Oct 18, 2010 at 4:57 PM

Thanks Mark,

Does make sense, I just couldn't see the wood for the trees last week. (CAML still fries my brain, it was the boolean / integer problem this time).

Thanks again