0

How could I use a caml query to only get the list items that are selected using the JavaScript Object Model?

<Where>
  <Eq>
     <FieldRef Name= ??? />
     <Value Type="Integer">1</Value>
  </Eq>
</Where>

For example, a user can select one, many, or all items in a list. I have a list on a page and I want to get the item(s) that are selected and do something with it. Thanks

1

You would not use a CAML query to do that. You can get the selected items using SP.ListOperations.Selection.getSelectedItems(ctx)

var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);

See this related answer.

  • Hi thanks for the reply. When I use the above, I get the id of the list item(s) selected. If I need to get the value of the fields in that list item, do I use the id of the items selected in a caml query? – Jshoe523 Mar 2 '15 at 18:29
  • Yes, exactly, you can create a CAML query to get the items with the specified IDs. Since you are working in JavaScript, this library might help you: camljs.codeplex.com . I have not used it yet, but I will the next time I am using CAML queries in JavaScript. – Dylan Cristy Mar 2 '15 at 18:35

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.