0

I am making Sharepoint hosted app and I am trying to get all lists

appContextSite = new SP.AppContextSite(context, hostweburl);
this.web = appContextSite.get_web(); //Code to get the cross domain
collList = this.web.get_lists();

this collList object retrive all list and i filter hidden list with get_hidden() so i removed hidden list.

But my problem is I get list like Form Templates, MicroFeed, Site Assets,Site Pages, and Style Library. I don't want this list because these lists are sharepoint created lists. Is there any idea how to filter this lists with some property or any other way.

Is there any way to get created by property for list through csom or jsom?

0

UPDATE

From reference: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splisttemplatetype.aspx

Microsoft Corporation products that are built on SharePoint Foundation, such as Microsoft SharePoint Server, can and do define additional list types. Also, Microsoft SharePoint Foundation farms where your solution is deployed may have custom list types created, for example, by adding a CAML ListTemplate Element (List Template) to a Feature or to the ONET.xml file of a custom site definition configuration. (Such custom list types should have ID values above 10000 to ensure that they do not conflict with numbers that will be used by Microsoft in future versions of SharePoint Foundation

Try below code:

function getList() {
        clientContext = new SP.ClientContext.get_current();    //pass your proper ClientContext
        web = clientContext.get_web();

        colList = web.get_lists();
        clientContext.load(colList);
        this.listInfoCollection = clientContext.loadQuery(colList);

        clientContext.executeQueryAsync(Function.createDelegate(this, this.onGetListSuccess), Function.createDelegate(this, onFail));
    }

    function onGetListSuccess(sender, args) {
        for(var i=0;i< this.listInfoCollection.length;i++)
        {
            clientContext.load(this.listInfoCollection[i]);
        }
        clientContext.executeQueryAsync(Function.createDelegate(this, this.onGetFilterList), Function.createDelegate(this, onFail));
    }

    function onGetFilterList(sender, args) {
        for (var i = 0; i < this.listInfoCollection.length; i++) {
        //in this if condition id > 10000 will return only custom lists & you can exclude unwanted list using template id 
            if (parseInt(listInfoCollection[i].get_baseTemplate()) > 10000 && !listInfoCollection[i].get_hidden()) {
                alert(listInfoCollection[i].get_title());
                //you desired logic
                    }
        }

Hope this will help you.

  • Thanks for your answer, but this will not work because 101 base template is for all doc lib so user created document lib also not displayed through this code. – Jinesh Kaneriya Apr 27 '16 at 7:42
  • my friend, you can add your desired condition in that if condition. I had put 101 for illustration only – Dikesh Gandhi Apr 27 '16 at 7:53
  • Yes but i can not found condition that show user created list and sharepoint(system) created list. Also i am making app so can't filter with name or anything. – Jinesh Kaneriya Apr 27 '16 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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