This SharePoint 2013 tutorial explains, how to get selected item id’s from a SharePoint 2013 list view by using JavaScript object model (jsom). Here I have a SharePoint 2013 list which has few items. Now in the All Items view I want to know on a button click what are items selected, basically I want to get the ids of the items.
Get selected item id from SharePoint 2013 list view using JSOM (JavaScript object model)
Here I have taken a button and on the button click, we are retrieving selected list item id from SharePoint list view using javascript.
Open your SharePoint 2013 site in the browser then open the list (All Items view). Then edit the page and click on Add a web part to add a web part. Then from the Media and Content select a Script Editor web part to the page. Then put the below code inside the script editor web part.
<input type='button' value='Get Item IDs' onclick="clickMethod();"/>
<br />
<script language="javascript" type="text/javascript">
function clickMethod() {
var ctx = SP.ClientContext.get_current();
var items = SP.ListOperation.Selection.getSelectedItems(ctx);
var mySeletedItems = '';
var i;
for (i in items)
{
mySeletedItems += '|' + items[i].id;
}
alert (mySeletedItems);
}
</script>
Now Save the page and select few items from the list and then click on the button, it will display you id’s of the selected items in a dialog box as shown in the fig below:
You may like following JSOM SharePoint tutorials:
- What is people picker and how we will use HTML Div as a People picker control in SharePoint Online?
- Create an organization chart from a list in SharePoint Online/2013/2016 using JavaScript
- Different ways to create auto increment column in SharePoint 2013/2016/Online list
- Get Current User Details Using JavaScript Object Model (jsom) and jQuery in SharePoint 2013/2016/Online
- Get current weather using JavaScript in SharePoint Online/2013/2016
- Update People Picker Group field using Rest API and jQuery in SharePoint 2013/2016
- SharePoint online: Add Columns or Fields to SharePoint List or Document Library using JavaScript Object Model (jsom)
- Various ECMA List field operations in SharePoint 2013
- How to create a list using jsom (JavaScript object model) in SharePoint?
- Retrieve all users from all groups using jsom in SharePoint Online
Hope this SharePoint tutorial explains, how to get selected item id from SharePoint 2013 list view using JSOM (JavaScript object model).
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SPGuides.com