There are five custom lists in a site collection, all have same content type. I would like to get all items from those five lists using JavaScript. Is there a way to get all items from all lists having a specific content type using JavaScript?

This is my code:

var clientContext = new SP.ClientContext.get_current();
var hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var parentContext = new SP.AppContextSite(clientContext, hostweburl);
var parentWeb = parentContext.get_web();
var listCollection = parentWeb.get_lists();
var list;
var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();

$(document).ready(function () {

function onGetUserNameSuccess() {
function onGetUserNameFail(sender, args) {
    message("Failed to get user name. Error:" + args.get_message(), "danger", "glyphicon glyphicon-remove");
context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail)

function getQueryStringParameter(paramToRetrieve) {

var params = document.URL.split("?")[1].split("&");
var strParams = "";

for (var i = 0; i < params.length; i = i + 1) {

    var singleParam = params[i].split("=");

    if (singleParam[0] == paramToRetrieve) {
        return singleParam[1];

function Filter() {

var listString = "";
var listEnumerator1 = listCollection.getEnumerator();
while (listEnumerator1.moveNext()) {
    var currentItm = listEnumerator1.get_current();
    listString = currentItm.get_title();

    var query = new SP.CamlQuery();
    query.set_viewXml("<View><Query><Where><And><Eq><FieldRef Name='Author'             /><Value Type='User'>" + user.get_title() + "</Value></Eq><Eq><FieldRef Name='ContentType' /><Value Type='Computed'>Nintex</Value></Eq></And></Where></Query></View>");

    var items = listCollection.getByTitle(listString).getItems(query);

    function onSuccess() {
        var itmString = "";
        var enumerator = items.getEnumerator();

        while (enumerator.moveNext()) {
            var currentItem = enumerator.get_current();
            var id = currentItem.get_id();
            itmString += "<div class='alert alert-danger divHeader' data-id='" + id + "' innerHTML=<label class='divHeader'>" + currentItem.get_item("Title") + "</label></div><div class='alert alert-warning divContent' id='" + id + "' style= 'display: none;' ></div>";

    function onFail(sender, args) {
        message("Error:" + args.get_message(), "danger", "glyphicon glyphicon-remove");

    clientContext.executeQueryAsync(onSuccess, onFail);

1 Answer 1


You can leverage SharePoint search APIs to get all the items. Pre-Requisites:

  1. Search configured with continuous crawl enabled.

You can use either Search REST APIs or KQL in JSOM.


  function getSearchResultsREST(queryText) {
    var url = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?querytext='" + queryText + "'";
    var executor = new SP.RequestExecutor(_spPageContextInfo.webAbsoluteUrl);
            url: url,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {/*Parse the data object to get your result */ },
            error: function (err) { alert(JSON.stringify(err)); }


function getSearchResultsJSOM(queryText)
    var clientContext = new SP.ClientContext.get_current();
    var contextSite = clientContext.get_site();
    var keywordQuery = new Microsoft.SharePoint.Client.Search.Query.KeywordQuery(clientContext);
    var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(clientContext);
    var results = searchExecutor.executeQuery(keywordQuery);
    context.executeQueryAsync(function (data) { /*Parse the data object to get your result */ }, function (err) { });

Now your query text will be something like :

ContentTypeID:<ID Of CType1> OR ContentTypeID:<ID Of CType2> OR ContentTypeID:<ID Of CType3 > OR ContentTypeID:<ID Of CType4> OR ContentTypeID:<ID Of CType5 >
  • Thank you very much Unnie for you kindly answer but this is the first time i use the search Query in JSOM and i need some more help please. if I have a div in HTML with id "allItmes". How can i print all the items title in this div in the JSOM methos Nov 15, 2015 at 21:41
  • I mean what im gonna write in that Place you have worte /*Parse the data object to get your result */ Nov 15, 2015 at 21:46
  • sharepointnutsandbolts.com/2013/01/… See this blog. Look at the success callback method where the JSON is parsed. Also look for samples on how to parse json
    – Unnie
    Nov 15, 2015 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.