Get current item id using JavaScript Client Object Model RRS feed

  • Question

  • I have a client query that query SharePoint list Items. Lets say it is a document library. I need to get the list item id of each. 

    I can query the Title of the document using this syntax.


    But when I try 


    for list item ID, it does not give a value. How can I solve this?

    Monday, December 23, 2013 10:10 AM


  • Hi Malin,

    If you're using the JavaScript Client Object Model, try using the SPListItem.get_item('key') method as in the example below:

    ExecuteOrDelayUntilScriptLoaded(function(){ var arrIds = []; var clientContext = new SP.ClientContext(); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml('<View><Query></Query></View>'); var items = clientContext.get_web().get_lists().getByTitle("Your List Title Here").getItems(camlQuery); clientContext.load(items); clientContext.executeQueryAsync(Function.createDelegate(this,function(){ var itemEnumerator = items.getEnumerator(); while(itemEnumerator.moveNext()){ var itemId = itemEnumerator.get_current().get_item('ID'); arrIds.push(itemId); } alert(arrIds); }), Function.createDelegate(this, function(){ alert("something went wrong"); })); },"SP.js");

    Monday, December 23, 2013 6:09 PM