1

Attempting to retrieve items from a list where field School_id is equal to a school_id javascript variable, and using SPServices GetListItems operation.

If I run the script without the CAMLQuery: Parameter, it returns all items on the list which is great, however when I add the Query to filter my returns I get

POST [server Address redacted] 500 (Internal Server Error)

I assume there's something wrong with my Query, I've already tried removing the tags but yields same result.

Is it possible that it actually is a server side error despite it successfully returning data with the Query absent?

  <script language="javascript" type="text/javascript">
    // http://spservices.codeplex.com/wikipage?title=GetListItems&referringTitle=Lists
    $(document).ready(function() {

    var school_id = getQueryVariable("school_id");  

  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Contacts",
    CAMLViewFields:  "<ViewFields><FieldRef Name='Title' /><FieldRef Name='FirstName' /></ViewFields>",
    CAMLQuery: "<Query><Where><eq><FieldRef Name='school_x0020_id'/><Value Type='Text'>" + "4440" + "</Value> </eq> </Where></Query>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).SPFilterNode("z:row").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + ", " + $(this).attr("ows_FirstName") + "</li>";
        $("#ContactsUL").append(liHtml);
      });
    }
  });
});
</script>

<ul id="ContactsUL"/>
1
  • next time use CamlJs to help you write the caml query for sharepoint, they have an amazing Chrome addin as well.
    – dinnouti
    Jan 6, 2017 at 16:21

3 Answers 3

1

Try this Query

CAMLQuery: "<Query><Where><Eq><FieldRef Name='school_x0020_id'/><Value Type='Text'>4440</Value></Eq></Where></Query>",
3
  • Thanks. After changing the casing in fieldref to match as well as it works now.
    – Essah
    May 25, 2015 at 9:04
  • I would have also checked your CAMLViewFields. <FieldRef Name='School_x0020_id' /> is not in there. And in the above answer, it would need School_x0020_id (capital letter), not what is above (which has a lowercase letter).
    – vapcguy
    Jan 6, 2016 at 14:51
  • how to fetch the calculated column from the splist in sp services? it it possible to fetch it and assign it o a string variable ? Apr 2, 2018 at 17:31
0

Try changing your

<eq>  </eq> 

tags to

<Eq> </Eq>

I think case matters for those tags.

0

I see a couple things,

  • eq should be Eq
  • is school id the name of your column? Make sure the casing is correct.
  • Lookup values should be represented like:

    <Eq> <FieldRef Name='RelatedIssues' LookupId='True' /> <Value Type='Lookup'>4440</Value> </Eq>

Also look at the Biwug CAML Designer for all your CAML querying needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.