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?
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:
Hope this will help.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With