Reading the list items Sharepoint 2010 client object model

14,290

Solution 1

try this one:

<View>
  <Query>
    <Where>
      <Eq>
        <FieldRef Name="Anchor" />
        <Value Type="Boolean">1</Value>
      </Eq>
    </Where>
  </Query>
</View>

in case if it doesn't work for you, follow next steps:

  1. Create a list view using standard functionality.
  2. Open it at SharePoint Designier and just copy CAML query from the code.

Hope this will help.

Solution 2

Remove the Query tags from the CAML query stored in myQueryString. The tags are added implicitly when the query is run.

It's tripped me up before, too. The insidious thing about it is that the query won't ever fail outright; sometimes it works, sometimes it doesn't, making it a pain to debug.

Share:
14,290
user346514
Author by

user346514

Updated on June 23, 2022

Comments

  • user346514
    user346514 almost 2 years

    I have a list where I am storing the image URLs and I am trying to read list of items and display the images on the page. For that I wrote the script something like below....

    <script type="text/javascript">
        function ViewItem()
        {
            var myQueryString = '<Query><Where><Eq><FieldRef Name="Anchor" /><Value 
    
    Type="Boolean">1</Value></Eq></Where></Query>'; 
    
            var context = new SP.ClientContext.get_current();
            var web = context.get_web();
            var list = web.get_lists().getByTitle('AnchorImageList');
            var myquery = new SP.CamlQuery();
    
            myquery.set_viewXml(myQueryString); 
    
            myItems = list.getItems(myquery);
    
    
            context.load(myItems, 'Include(Title,ImageURL)');
            context.executeQueryAsync(Function.createDelegate(this, this.success), 
    
    Function.createDelegate(this, this.failed));
        }
        function success() 
        {
    
            var LinkURL= "";
            var ImageURL="";
            var ListEnumerator = this.myItems.getEnumerator();
            while(ListEnumerator.moveNext())
            {
                var currentItem = ListEnumerator.get_current();
                LinkURL = currentItem.get_item('Title') ;
                ImageURL= currentItem.get_item('ImageURL');
                document.write('<img src="' + ImageURL+ '"+>');
                alert(LinkURL);
    
            }
    
        }
        function failed(sender, args) 
        {
            alert("failed. Message:" + args.get_message());
        }
    </script>
    <a href="#" onclick="Javascript:ViewItem();">View Items</a>
    

    In my CAML query I am trying to filter items which are tagged yes for "Anchor?"(yes/no column).

    But I am seeing all the results even though I tagged few items not to display. What I am doing wrong here. Please someone help me. Also,after the images are loaded on the page, the page is still showing the wheel as if it is processing something. Do I need to do something for this?