SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a code that read all items from List Airtports. I want to get selected Item from List. How can i change below code to get it done, Please help

function ReadListItem() {

        var listTitle = "Airports";

        //Get the current client context
        context = SP.ClientContext.get_current();

        var airportList = context.get_web().get_lists().getByTitle(listTitle);

        var camlQuery = SP.CamlQuery.createAllItemsQuery();

        this.listItems = airportList.getItems(camlQuery);


        context.executeQueryAsync(ReadListItemSucceeded, CreateListFailed);


    function ReadListItemSucceeded(sender, args) {

        var itemsString = '';
        var enumerator = listItems.getEnumerator();

        while (enumerator.moveNext()) {

            var listItem = enumerator.get_current();
            itemsString += 'AirportName: ' + listItem.get_item('AirportName') + ' AirportCode: ' + listItem.get_item('AirportCode') + '\n';



share|improve this question
What do you mean by "get selected item"? A specific item? This currently loops through all items in the list. Can you be more clear on what you are trying to do? – RJ Cuthbertson Aug 2 '12 at 13:20

If you mean a standard list view, you can use SP.ListOperation.Selection.getSelectedItems to get the id of the selected list item. Then you can retrieve the whole item (or a part of properties you need):

Here is an example:

var listGuid = SP.ListOperation.Selection.getSelectedList()
//in this example only first selected item is retrieved
var selectedItemId = SP.ListOperation.Selection.getSelectedItems()[0].id
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var lists = web.get_lists();
var list = lists.getById(listGuid);
var item = list.getItemById(selectedItemId);
ctx.executeQueryAsync(function() {
    var title = item.get_item("Title");
}, function(){alert("error");});
share|improve this answer

Your Answer


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.