I have a custom list template (STP) in my list template gallery. I can retrieve the list template using the client object model in javascript. But it's not clear how to create a new list from that template. This is what I am trying:
var site = SP.ClientContext.get_current().get_site();
var web = SP.ClientContext.get_current().get_web();
this.result = site.getCustomListTemplates(web);
SP.ClientContext.get_current().load(this.result);
function retrieveTemplates_fail() { }
function retrieveTemplates_success()
{
var en = this.result.getEnumerator();
while (en.moveNext())
{
var item = en.get_current();
if (item.get_name() === 'mycustomtemplate')
{
var listCreationInfo = new SP.ListCreationInformation();
listCreationInfo.set_title('testfromtemplate');
listCreationInfo.set_templateFeatureId(item.get_featureId());
listCreationInfo.set_templateType(item.get_listTemplateTypeKind());
SP.ClientContext.get_current().get_web().get_lists().add(listCreationInfo);
function createList_fail() { alert('fail') };
function createList_success() { alert('success') };
SP.ClientContext.get_current().executeQueryAsync(
Function.createDelegate(this, createList_success),
Function.createDelegate(this, createList_fail)
);
}
}
}
SP.ClientContext.get_current().executeQueryAsync(
Function.createDelegate(this, retrieveTemplates_success),
Function.createDelegate(this, retrieveTemplates_fail)
);
The code executes successfully and the list is created, but it is not based on my template. It's just a generic list with a title column. How can I get the code to base the new list on my template?