Monday, November 25, 2013

Creating list using Java Script Client Object Model in SharePoint 2010


var oList;

 function createList()
 {
    var clientContext = new SP.ClientContext('/');
    var oWebsite = clientContext.get_web();

   var listCreationInfo = new SP.ListCreationInformation();
   listCreationInfo.set_title('My Announcements List');
   listCreationInfo.set_templateType(SP.ListTemplateType.announcements);

   this.oList = oWebsite.get_lists().add(listCreationInfo);
   clientContext.load(oList);

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

 function onQuerySucceeded()
{
        var result = oList.get_title() + ' created.';
        alert(result);
}


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


No comments:

Post a Comment