I'm having a difficult time creating custom lists using the SP JS API. Here's what I'm attempting to do:
var lciTasksList = new SP.ListCreationInformation();
lciTasksList.set_title('ProjectTasks');
lciTasksList.set_description('Project Tasks');
lciTasksList.set_templateFeatureId('00BFEA71-DE22-43B2-A848-C05709900100');
var tasksList = newWeb.get_lists().add(lciTasksList);
context.executeQueryAsync(
Function.createDelegate(this, function () {
alert('lists created');
}),
Function.createDelegate(this, function (sender, args) {
alert('lists creation failed');
})
);
The templateFeatureId is a custom list template that is based on the Task list type, with 1 additional custom Choice field. The execution method always ends in failure with
Cannot complete this action. Please try again.
Has anyone had success creating a list dynamically using a custom list template? My ultimate goal here is to use the JS API to create a new subweb (which works fine) and add several lists with custom columns. Is there another way to accomplish the same task?
Any insights would be much appreciated.
* UPDATE *
So I've gone with adding fields manually using the following:
taskList.get_fields().addFieldAsXml('<Field ID="{d2861db8-e36f-4c5e-8168-f7da8b010443}" Name="pdProjectStatus" DisplayName="Project Status" Type="Choice" Required="TRUE" ShowInDisplayForm="TRUE" ShowInEditForm="TRUE" ShowInViewForms="TRUE" ShowInNewForm="TRUE" Indexed="TRUE"><CHOICES><CHOICE>Active</CHOICE><CHOICE>Archived</CHOICE><CHOICE>Proposed</CHOICE></CHOICES></Field>'
, true
, SP.AddFieldOptions.AddToDefaultContentType
);
Still would be interesting to know if the template approach is available, either by a custom list template or by adding pre-existing custom site columns. Adding the fields in this way seems awfully inefficient, especially considering the Choice field type.