ECMA Script: To create a new SharePoint 2010 list

 

<script language="ecmascript" type="text/ecmascript">

 

    var clientContext = null;

    var oWeb = null;

    var oListColl = null;

    var oList = null;

    var listCreationInfo = null;

  

 

    function createList() {

        clientContext = new SP.ClientContext.get_current();

        oWeb = clientContext.get_web();

        listCreationInfo = new SP.ListCreationInformation();

        listCreationInfo.set_title('Custom List');

        listCreationInfo.set_templateType(SP.ListTemplateType.genericList);

        oList = oWeb.get_lists().add(listCreationInfo);

        clientContext.load(oList);

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

    }

 

    function onQuerySucceeded() {

       

        alert(oList.get_title() + ' created successfully.');

    }

 

    function onQueryFailed(sender, args) {

        alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

    }

 

 

 

</script>

<input id="btnCreateList" onclick="createList()" type="button" value="Create Custom List"/>