0

Hi I'm in need of some help with a caml query. I have 1 column in my list, that have 3 different choice.

I want to query out items if the choice is equal to YES

This is my code:

var context = new SP.ClientContext.get_current();
enter code hered

var web = context.get_web(); 
var list = web.get_lists().getByTitle("MyList");  

var viewXml = String.format(
"<View>" +
"<Query>" +
"<Where>" +
"<Eq>" +
"<FieldRef Name='MyChoiceField' />" +
"<Value Type='Choice'>YES</Value>" +
"</Eq>" +
"</Where>" +
"</Query>" +
"</View>");

var query = new SP.CamlQuery();
query.set_viewXml(viewXml);
this.items = list.getItems(query);

The rest of the code works except the query

  • Is it a typo, there is no + after "</Where>" – Nadeem Yousuf Feb 28 '14 at 14:55
  • In my environment there is a +, i missed it here – Anders Feb 28 '14 at 14:58
  • what is the actual name of the field. Perhaps you may not be using the internal name of the field. – Nadeem Yousuf Feb 28 '14 at 15:03
  • Updated it as the answer so that it can be closed. – Nadeem Yousuf Feb 28 '14 at 15:54
2

Check the internal name of the field. The CAML query needs the internal name of the field.

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.