Caml Query, comment/uncomment?

Jan 9, 2012 at 12:43 AM

Hi,
I am stumped by this issue below.  The following code works.  But when I go to uncomment the CAMLQuery, it doesn't work.  Does anyone know what the issue might be? Thanks for your help!

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" language="javascript"  src="../../Resources/SPRUCE_2010/Scripts/jquery.SPServices-0.6.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Image Gallery",
    CAMLViewFields: "<ViewFields Properties='True' />",
    //CAMLQuery: "<Query><Where><Eq><FieldRef Name='Display' /><Value Type='Text'>Yes</Value></Eq></Where></Query>",
    CAMLRowLimit: 1, 
	completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
		var spotlightimage = "<img src='"+$(this).attr("ows_EncodedAbsUrl")+"' style='width:240;height:163;border:0' />";
        $("#SpotlightDiv").append(spotlightimage);
      });
    }
  });
});
</script>
<div id="SpotlightDiv"/>

 

Jan 9, 2012 at 2:09 AM

Can you elaborate a bit more on what you are experiencing?  I've added some console logs to your code that will allow you to pinpoint more of what is going on.  Make sure your browser's dev tools are open when running this code. 

 

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript" language="javascript"  src="../../Resources/SPRUCE_2010/Scripts/jquery.SPServices-0.6.2.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Image Gallery",
    CAMLViewFields: "<ViewFields Properties='True' />",
    //CAMLQuery: "<Query><Where><Eq><FieldRef Name='Display' /><Value Type='Text'>Yes</Value></Eq></Where></Query>",
    CAMLRowLimit: 1, 
	completefunc: function (xData, Status) {
console.log(Status);
console.log(xData.responseText);
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
		var spotlightimage = "<img src='"+$(this).attr("ows_EncodedAbsUrl")+"' style='width:240;height:163;border:0' />";
        $("#SpotlightDiv").append(spotlightimage);
      });
    }
  });
});
</script>
<div id="SpotlightDiv"/>

Coordinator
Jan 9, 2012 at 1:12 PM

As Matt mentions, understanding a bit more about what happens would be useful. Do you get no results? Results you don't expect? The first thing I'd check is whether 'Display' is the StaticName for the column and that the type is correct.

M.

Jan 9, 2012 at 2:28 PM

Thanks for reaching out.  What I am trying to do here is display the image with a "Yes" under the Display column.  The images is located in a picture library called "Image Gallery".  

When I go to add the CAMLquery, the script does not does not work.  It does not show any images.   But when the code is commented out, one of the images in the folder does appear.  

Is there an internal name for Display?  I couldn't find anything online.  

Jan 9, 2012 at 4:14 PM

this is the the console error i got, "NetworkError: 500 Internal Server Error - https://dev.sprucecommunity.org/_vti_bin/Lists.asmx".  Any ideas?

Coordinator
Jan 9, 2012 at 4:31 PM

Have you looked at the SPDisplayReleatedInfo function? It may do exactly what you want.

The easiest way to figure out what the StaticName of the column is is to go to the List Setings, and edit that column. The StaticName will be on the URL in the Query String, but it will be encoded.

If you created the Display column and named in Display, then that's the StaticName.

M.

Jan 9, 2012 at 4:32 PM

Using the web services this long, I've never seen that particular error message.  Marc would know exactly what this means though...  No pressure :)

Just being cheeky, I tried the URL...  The connection is closed when visiting: https://sprucecommunity.org.  However visiting: http://sprucecommunity.org works just fine.  Definitely a weird issue you are having...

Jan 9, 2012 at 7:54 PM

I know why I got an error.  Display is a checkbox type.   I just had to change value type = 'checkbox'!   Thanks for helping!

Jan 9, 2012 at 8:01 PM
CAMLQuery: "<Query><Where><Eq><FieldRef Name='Display' /><Value Type='Checkbox'>Yes</Value></Eq></Where></Query>",

Question about the value input, is that the correct way to choose your value?  or is it, <Yes /> ?   I only have two choices, yes or no for the checkbox.
Coordinator
Jan 9, 2012 at 8:02 PM
Edited Jan 9, 2012 at 8:03 PM

That makes sense. Glad you worked it out. And yes, you're providing the value correctly.

M.

Jan 9, 2012 at 8:14 PM

hmm  <Value Type='Checkbox'>Yes</Value> gave me an error.  

I also tried <Value Type='Checkbox'><Yes/></Value> but that returned an image with "no" as a display.  So i then tried <Value Type='Checkbox'><No/></Value>  but it still gave me the same image as like when i had <Yes/>.

Any ideas?

Coordinator
Jan 9, 2012 at 8:26 PM

Sorry, I wasn't paying enough attention. A Yes/No column is a boolean, so this ought to work for you:

    CAMLQuery: "<Query><Where><Eq><FieldRef Name='Display' /><Value Type='Boolean'>1</Value></Eq></Where></Query>",

M.