Getting the Item ID from the ECB (Edit Control Block) using JavaScript
-
10-12-2019 - |
Question
I know I can use {ItemId} to pass it to the URL like so:
<UrlAction Url="~site/_layouts/ConvertItem/ConvertItem.aspx?ListId={ListId}&ItemId={ItemId}&ItemUrl={ItemUrl}"/>
However, I am using JavaScript exclusively. Can I get the ItemID using JavaScript?
<UrlAction Url="javascript:function copyListItems() { res = SPListItemCopy.Resources[_spPageContextInfo.currentLanguage];var listItemID = {ItemId};var listId = {ListId};var context = SP.ClientContext.get_current();var list = context.get_web().get_lists().getById(listId);var item = list.getItemById(listItemID); ..."/>
Solution
I think the token should be getting replaced anyway, is you second example not working ? also you might nee to wrap the vars with single quotes like var listId = '{ListId}' also your JavaScript functions is not self calling, I think it should be javascript: function copyListItems(){}()
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange