0

I am trying to create a list using custom list template in SPO but I am getting error as

Uncaught TypeError: Cannot read property '$39_0' of undefined at SP.ClientRequest.$3C_0 (sp.runtime.js:2) at SP.ClientRequest.$3H_0 (sp.runtime.js:2) at SP.ClientContext.executeClientRequestAsync (sp.runtime.js:2) at SP.ClientContext.executeClientRequestAsync (sp.js:2) at Array. (sp.runtime.js:2) at ScriptResource.axd?d=Mc2groXhycX9-9HOevd9H4YLhMuHyaSg48Rru2qK9d69NSJpSVwhtPBb0sN4TWO7LXsL-cZypD02_ImoL6winpWs7RM5QvD0e7mhm8jDyFo75eDGwkHkoO8XV-E7MUPVXTIlZQ7SquetAU3C_OIUJ0XuVIYjvcS0lyW5WOx73PN_-uCftQApNVlltFgOURJ60&t=ffffffff85e60464:5 at Sys.Net.WebRequest.completed (ScriptResource.axd?d=Mc2groXhycX9-9HOevd9H4YLhMuHyaSg48Rru2qK9d69NSJpSVwhtPBb0sN4TWO7LXsL-cZypD02_ImoL6winpWs7RM5QvD0e7mhm8jDyFo75eDGwkHkoO8XV-E7MUPVXTIlZQ7SquetAU3C_OIUJ0XuVIYjvcS0lyW5WOx73PN_-uCftQApNVlltFgOURJ60&t=ffffffff85e60464:5) at XMLHttpRequest._onReadyStateChange (ScriptResource.axd?d=Mc2groXhycX9-9HOevd9H4YLhMuHyaSg48Rru2qK9d69NSJpSVwhtPBb0sN4TWO7LXsL-cZypD02_ImoL6winpWs7RM5QvD0e7mhm8jDyFo75eDGwkHkoO8XV-E7MUPVXTIlZQ7SquetAU3C_OIUJ0XuVIYjvcS0lyW5WOx73PN_-uCftQApNVlltFgOURJ60&t=ffffffff85e60464:5)

Below is my code snippet

function onQuerySucceeded(sender, args) {
    alert("Success");
}
function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
}
function CreateListUsingTemplate() {
    hideProcessingDialog();
    debugger;
    var rootCTX = new SP.ClientContext('SharePoint URL');
    var web = rootCTX.get_web();

    var listTemplates = rootCTX.get_site().getCustomListTemplates(web);
    rootCTX.load(listTemplates);
    rootCTX.executeQueryAsync(function() {
        var en = listTemplates.getEnumerator();
        while (en.moveNext()) {
            var item = en.get_current();
            if (item.get_name() === _templateName) {
                var listCreationInfo = new SP.ListCreationInformation();
                listCreationInfo.set_title('Actions');
                listCreationInfo.set_description('Actions');
                listCreationInfo.set_listTemplate(item);
                listCreationInfo.set_templateFeatureId("{00BFEA71-A83E-497E-9BA0-7A5C597D0107}");
                listCreationInfo.set_templateType(item.get_listTemplateTypeKind());
                var ctx = new SP.ClientContext(_projectSiteURL);
                ctx.get_web().get_lists().add(listCreationInfo)
                    // ctx.load(myList);
                ctx.executeQueryAsync(
                    Function.createDelegate(this, this.onQuerySucceeded),
                    Function.createDelegate(this, this.onQueryFailed)
                );
                // ctx.executeQueryAsync(function() {
                //     hideProcessingDialog();
                //     alert('List created');
                // }, function(sender, args) {
                //     hideProcessingDialog();
                //     alert('Failed to create list');
                //     alert(args.get_message());
                // }, function() {
                //     alert('');

                // });
            }

        }

    }, function(sender, args) {

        alert('failed to get list template');
        alert(args.get_message());

    });

Refernce Use

Thanks in advance

0

I think,set_listTemplate() of ListCreationInformation is not supported. because of this you are getting porperty undefined error. You will have to use CustomSchemaXml property of ListCreationInformation to create list(using your custom template).Create schema.xml for your custom list and pass this as a string to CustomSchemaXml property in javascript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.