1

Is there is a way to retrieve the List Item Id (ID) that you are currently viewing (Display.aspx from) in javascript.

I have searched through ctx and the _spPageContextInfo but have not found any solutions. Most the mentions online speak of getting the selected item in the AllItems.aspx view but I am interested in getting it in the Display Form.

3 Answers 3

2

You can do this with javascript and JSRequest.

The ID should be passed in via the URL, (ie. 'DispForme.aspx?Id=11'), then use the below code to retrieve the '11'..

JSRequest.EnsureSetup(); 
var itemId = JSRequest.QueryString["ID"];
2
  • I believe he is asking about List Id and not Item Id. Jun 25, 2015 at 8:02
  • I made a typo, you were correct in your assumption Simon.
    – Mido
    Jun 25, 2015 at 8:19
1

ItemID, just use the URL:

var itemIdINT = GetUrlKeyValue("ID", false, location.href);

ListId in the SP forms there are a couple of fields where you can extract the List GUID via jquery... e.g.:

var listIdGUID = $('[id^=_ListSchemaVersion_]').attr('id').toString().match(new RegExp(/\{(.*?)\}/))[1];
0

You may use something like this:

function getQS(key) {
  var regex=new RegExp('[\\?&]'+key+'=([^&#]*)');
  var qs=regex.exec(window.location.href);
  return qs[1];
}

var itemID = getQS('ID');

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.