Blog

SharePoint development can be ‘interesting’, and by that I mean ‘infuriating’. So, this is where I’m going to record the most time-consuming and obscure solutions - mainly to aid my own memory…

SharePoint 2013 - Create list from custom list definition.

The first obscure problem I came across while doing SharePoint 2013 app development was creating a list from a custom list definition in JavaScript.

Creating a custom list from a content type is well documented, and very easy to achieve in Visual Studio 2012.

But what if you want to create a list that you’ve created from a content type? Well the trick is to create the ListCreationInformation object, and call the set_templateFeatureId method passing the Feature GUID that contains your list definition. See the code below:

    function MCCreateList(listName) {
        var listCreationInfo = new SP.ListCreationInformation();
        listCreationInfo.set_title(listName);
        listCreationInfo.set_description("My description.");
        listCreationInfo.set_templateFeatureId('a7c90836-8885-41c8-945a-0076d9e7cfa8');
        listCreationInfo.set_templateType('10000');

        this.oList = web.get_lists().add(listCreationInfo);

        context.load(oList);

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