0

I have used the below code to do the same bt it shows some error in the alert..

<script type="text/javascript">

var siteUrl = '/sites/MySiteCollection';
_spBodyOnLoadFunctionNames.push("retrieveAllListProperties");
function retrieveAllListProperties() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    this.collList = oWebsite.get_lists();

    clientContext.load(collList);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    var listInfo = '';

    var listEnumerator = collList.getEnumerator();

    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += 'Title: ' + oList.get_title() + ' Created: ' + oList.get_created().toString() + '\n';
    }
    alert(listInfo);
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


</script>
2
  • Please elaborate the error that you get. You shall be able to see the error in the error console when you press F12 key. Jul 7, 2015 at 11:30
  • Do you want the count or information of list like title and created and so on?
    – users1100
    Jul 7, 2015 at 12:25

2 Answers 2

2

A bit easy way to get the list information using REST Query.

You can try following code:

try {
    //REST Query to get the display form url 
    jQuery.ajax(
    {
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/Lists",
        type: "GET",
        async: false,
        headers: { "Accept": "application/json;odata=verbose" },
        success: function (data, textStatus, xhr) {
            if(data.d.results.length > 0){
                var coll = data.d.results;
                for(var i=0; i < coll.length; i++){
                    listInfo += 'Title: ' + coll[i].Title + ' Created: ' + coll[i].Created + '\n';
                }
                alert(listInfo);
            }
        },
        error: function (data, textStatus, xhr) {
            alert("Error while getting data");
        }
    });
}
catch (ex) {
    alert(ex);
}

Hope this helps to solve your query!!

0

This javascript code works.....

<script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(init,'sp.js');
    var clientcontext;
    var website;
    var Lists;
    function init(){
    clientcontext=SP.ClientContext.get_current();

    website=clientcontext.get_web();

    Lists=website.get_lists();
    clientcontext.load(Lists);
    clientcontext.executeQueryAsync(onRequestSucceeded, onRequestFailed);


    }
    function onRequestSucceeded(){

    var listInfo = '';

        var listEnumerator = Lists.getEnumerator();

        while (listEnumerator.moveNext()) {
            var List = listEnumerator.get_current();
        listInfo += 'Title: ' + List.get_title() + '<br>';
        var camlQuery = new SP.CamlQuery();
            var q = "<Where><Eq><FieldRef Name='StatusID' /><Value Type='Integer'>1</Value></Eq></Where>";
            camlQuery.set_viewXml(q);
            this.listItems = List.getItems(camlQuery);
            clientContext.load(listItems, 'Include(Id)');
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onListItemsLoadSuccess), 
            Function.createDelegate(this, this.onQueryFailed));

        }

        document.getElementById('list').innerHTML=listInfo;


        }

        function onQueryFailed(sender, args) {
            alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
        }


    }

    function onRequestFailed(sender, args) {
        alert('Error: ' + args.get_message());
    }
    </script>
    <div>
    <span id='list'></span>
    <span id='cnt'></span>
    </div>

Your Answer

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

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