سؤال

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.

هل كانت مفيدة؟

المحلول

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"];

نصائح أخرى

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];

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');
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top