Hi all,
I want to create a library from a template, the code that been testing it:
and this modifies the example below but I have not had any success, do not know how to associate a custom list.
thank you very much! for their help
Example :
function runCode() {
var clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var web = clientContext.get_web();
var listTemplates = web.get_listTemplates();
var templateTestLibrary = listTemplates.getByName(‘TemplateLibrary_v23’);
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title(‘test creation library’);
// listCreationInfo.set_templateType(SP.ListTemplateType.discussionBoard);
listCreationInfo.set_templateType(templateTestLibrary);
this.list = web.get_lists().add(listCreationInfo);
clientContext.load(list);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
}
function onQuerySucceeded() {
var result = ‘ Added Discussion Board: ‘ + this.list.get_title();
alert(result);
}
function onQueryFailed(sender, args) {
alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}
Interesting…
I tried to dig a little bit deeper. What I found:
1. I tried to list available templates but was unable to find my custom template.
2. I was able to create list providing direct values:
listCreationInfo.set_templateType(SP.ListTemplateType.genericList);
listCreationInfo.set_templateFeatureId(“00BFEA71-DE22-43B2-A848-C05709900100”);
3. If you really need to find template by name you should find a way to get it. Maybe you can iterate templates library …