Tell me more ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I open list item for editing and want to execute some javascript for this but i cann't retrieve item Id in Edit form.

I use following code:

var context = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(context);

But items collection is empty. On "View all" List form this code work well. Throubles only in EditForm. Can anyone help me?

share|improve this question

1 Answer

up vote 4 down vote accepted

The Item ID is passed via url to the Edit Form. so you cab get it using this : _spGetQueryParam('id') Let me know if this works.

share|improve this answer
When i open EditForm and execute command in javascript console 'window.location' i see 'sharepoint/TestSite/Lists/ListForUser3/ListAll.aspx'; There is no anyone params. I'm helpless. – Fobos Jan 30 at 15:03
Because you open your edit form in a popup, the context refers to the host page (ListAll.aspx). To see the parameters of your Edit Form do the following : 1- Go to the list settings and open the Advanced Settings Section. 2- Change the Parameter : Open the pages in a popup to No. come back to the list and open the edit form. now the you can test if your id is here – must19 Jan 30 at 15:11
I want to allow user additional functionality when he works with my list. If he selects any item in list and press standart sharepoint "Edit button" standart popup edit window will be presented. And I must to work with that window and somehow retrieve item ID in him. – Fobos Jan 30 at 15:18
To Add functionnalities you must add your code in the EditForm.aspx page and in your code use _spGetQueryParam('id') to retrieve the ID of the current item. – must19 Jan 30 at 16:05
_spGetQueryParam('id') works well, thanks! – Fobos Jan 31 at 7:42
show 1 more comment

Your Answer

 
discard

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.