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());
}
Good Morning all !!
To find the Custom Template use the following code
this.colltemplate = SP.ClientContext.get_current().get_site().getCustomListTemplates(SP.ClientContext.get_current().get_web());
clientContext.load(colltemplate);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onTemplatesSucceeded), Function.createDelegate(this, this.onTemplatesFailed));
seeketh another way.
thank you very much
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 …
Hello all,Â
Thanks Sigitas for your reply, But I have not been successful,
If I assign this parameter error occurs and if I assign eg ‘101’Â Document Library.
Create the library, but does not use the template but the standard of Documents
listCreationInfo.set_title(‘Test_Biblioteca’);
listCreationInfo.set_description(‘prueba’);
//Â If you do not assign a value according to this list fails me:
// http://msdn.microsoft.com/enus/library/lists.lists.addlist (v = office.12). Aspx
listCreationInfo.set_templateType(‘101’); //Â
listCreationInfo.set_templateFeatureId(this.colltemplate.get_item(7).get_featureId());
this.list = web.get_lists().add(listCreationInfo);
clientContext.load(list);
thanks for the help,Â
sorry, changed only one part of the code. In the last example should be:
listCreationInfo.set_templateFeatureId(this.colltemplate.get_item(7).get_featureId());
Hello all ,Â
Thanks Sigitas,Â
this is the code with which to retrieve the template, but when I want to create the library generates an error message.
                       “Input string was not in a correct format”
Code Javascript add ListÂ
this.templateTestLibrary = this.colltemplate.get_item(7);
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title(‘Test_Biblioteca’);
listCreationInfo.set_templateType(this.colltemplate.get_item(7).get_featureId()); //
this.list = web.get_lists().add(listCreationInfo);
clientContext.load(list);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
XML , Request – /vti_bin/client.svc
<Request xmlns=”http://schemas.microsoft.com/sharepoint/clientquery/2009″ SchemaVersion=”15.0.0.0″ LibraryVersion=”16.0.0.0″ ApplicationName=”Javascript Library”>
<Actions>
<ObjectPath Id=”11″ ObjectPathId=”10″ />
<ObjectPath Id=”13″ ObjectPathId=”12″ />
<ObjectIdentityQuery Id=”14″ ObjectPathId=”12″ />
<Query Id=”15″ ObjectPathId=”12″>
<Query SelectAllProperties=”true”>
<Properties>
<Property Name=”Description” ScalarProperty=”true” />
<Property Name=”TemplateFeatureId” ScalarProperty=”true” />
<Property Name=”Title” ScalarProperty=”true” />
</Properties>
</Query>
</Query>
</Actions>
<ObjectPaths>
<Property Id=”10″ ParentId=”4″ Name=”Lists” />
<Method Id=”12″ ParentId=”10″ Name=”Add”>
<Parameters>
<Parameter TypeId=”{e247b7fc-095e-4ea4-a4c9-c5d373723d8c}”>
<Property Name=”CustomSchemaXml” Type=”Null” />
<Property Name=”DataSourceProperties” Type=”Null” />
<Property Name=”Description” Type=”Null” />
<Property Name=”DocumentTemplateType” Type=”Number”>0</Property>
<Property Name=”QuickLaunchOption” Type=”Number”>0</Property>
<Property Name=”TemplateFeatureId” Type=”Null” />
<Property Name=”TemplateType” Type=”Guid”>{00bfea71-e717-4e80-aa17-d0c71b360101}</Property>
<Property Name=”Title” Type=”String”>Test_Biblioteca</Property>
<Property Name=”Url” Type=”Null” />
</Parameter>
</Parameters>
</Method>
<Property Id=”4″ ParentId=”0″ Name=”Web” />
<StaticProperty Id=”0″ TypeId=”{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}” Name=”Current” />
</ObjectPaths>
</Request>
any ideas?, thanks for the help