Create a List from a List Template using ECMA Script
<input id="btnCreateCustomList" onclick="CreateCustomList()" type="button" value="Create List"/>
<script language="ecmascript" type="text/ecmascript">
var clientContext = null;
var oWeb = null;
var oListColl = null;
var oList = null;
var listCreationInfo = null;
function CreateCustomList() {
clientContext = new SP.ClientContext.get_current();
oWeb = clientContext.get_web();
listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title('Test 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>
SP.ListTemplateType.GenericList
SP.ListTemplateType.DocumentLibrary
SP.ListTemplateType.Survey
SP.ListTemplateType.Announcements
SP.ListTemplateType.Contacts
SP.ListTemplateType.Events
SP.ListTemplateType.Tasks
SP.ListTemplateType.DiscussionBoard
SP.ListTemplateType.PictureLibrary
SP.ListTemplateType.DataSources
SP.ListTemplateType.XmlForm
SP.ListTemplateType.NoCodeWorkflows
SP.ListTemplateType.WorkflowProcess
SP.ListTemplateType.WebPageLibrary
SP.ListTemplateType.CustomGrid
SP.ListTemplateType.WorkflowHistory
SP.ListTemplateType.GanttTasks
SP.ListTemplateType.IssuesTracking
Source :
Complete Reference
Comments
Post a Comment