Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this 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 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 at 18:35
    
That makes sense. Thanks for the explanation –  Jshoe523 Mar 2 at 18:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.