Get list items from view using JavaScript (jsom) in SharePoint Online/2013/2016

This SharePoint tutorial, we will discuss how to get list items from view using JavaScript (jsom) in SharePoint Online or SharePoint 2013/2016.

Here I will show, how we can retrieve list items from a particular view in SharePoint using JavaScript Object Model code.

SharePoint JavaScript get list items from view

Below is the jsom code to get list items from view, which you can write inside a script editor web part or a content editor web part.


function getItemsFromView(listTitle, viewTitle)
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle("DemoList");
var view = list.get_views().getByTitle("My Test view");
function(sender, args) {getItemsFromList(listTitle, “<View><Query>” + view.get_viewQuery() + “</Query></View>”)},
function(sender, args) {alert(“error: ” + args.get_message());}

function getItemsFromList(listTitle, queryText)
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
var query = new SP.CamlQuery();
var items = list.getItems(query);
var listEnumerator = items.getEnumerator();
var i = 0;
while (listEnumerator.moveNext())
alert(“items retrieved: ” + i);
function(sender, args) {alert(“error in inner request: ” + args.get_message());}

You may also like following SharePoint jsom tutorials:

Once you run the above code, you can see it will display all the items from the list view in SharePoint.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)


Bijay Kumar

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