I tried so many ways to get list item id but could not. Ofcourse i got one solution but it is not much proper solution. Can anyone give smart solution to get list item id by using js. I'm using sp 2010.

I tried this solution:

function getQuerystring(key, default_)

  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);

  if(qs == null)
    return default_;

    return qs[1];
 var itmID = getQuerystring('ID');

But it is not good way to get list item id,,.. Please help me to solve this. Thank you.

  • Where is the information about this ItemID? Is it in query string. If it is there, can you share how the url looks like? Commented Mar 3, 2014 at 7:21
  • 1
    Not sure what you are looking for. In the comments of one of the answers it looks you want to get the list item id of the item which is selected in List View Webpart. And in other comment, it looks like you want to get it from query string. If you want to get a proper answer, you should try to explain your question properly. Commented Mar 3, 2014 at 11:25

2 Answers 2


If you want to get the id of the document/item which is selected you can use this(source):

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

for (i in items){
    myItems += '|' + items[i].id; //String with all the IDs of the selected documents/items

And here is another way to get the selected items.

  • Thanks for your reply Mbauer.. I placed ur code and i took" var itmID=items[i].id " in for loop but didn't get id. Commented Mar 3, 2014 at 7:13
  • I updated my answer. You can also look here: sharepoint.stackexchange.com/questions/11169/…
    – mbauer
    Commented Mar 3, 2014 at 8:08
  • I seen your post but unable to get current list item id. And you said in the above, myItems has string with all id's.. here how can i retrieve current list item id from those id's?? Commented Mar 3, 2014 at 8:54
  • the string myItems contains all IDs of the selected documents/items
    – mbauer
    Commented Mar 3, 2014 at 9:38
  • understood mbauer... the how can we separate current item id from those all id's? Commented Mar 3, 2014 at 9:40

I assume you need to get Item Id from query string:

How to get query string values:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

For more details refer How can I get query string values in JavaScript?


console.log(getParameterByName('ID')); //print List Item Id

The function SP.ScriptHelpers.getDocumentQueryPairs could be used to parse the query string in SharePoint 2013. The following example demonstrates how to retrieve List Item Id:

         var pairs = SP.ScriptHelpers.getDocumentQueryPairs();
         var itemId = pairs.ID; //get Item Id

      }, 'SP.init.js');
  • Hi vadim.. it is also same like the way what im currently using . Any alternative techniques to get list item id? Thank you. Commented Mar 3, 2014 at 11:14
  • Hi praveen, the answer has been updated with example how to retrieve list item id using built-in SharePoint capabilities Commented Mar 3, 2014 at 12:30
  • Thanks for that Vadim... but which is not working on sp 2010. Commented Mar 3, 2014 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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