1

I am developing SharePoint Hosted app and I want to create lists. I have lists schema XML files. I want to use that schema and create list using JavaScript. I have tried the following code

function createListXML() {
var listName="ParentLT"
debugger;
$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('WorkFlowXAML')/items?$select*&$filter= Title eq 'ParentLT'",
    type: "GET",
    headers: {
        "accept": "application/json;odata=verbose",
    },
    success: function (data) {
        debugger;
        //fetched custom schema
        listxml = data.d.results[0].XAMLSchema;
        var context = new SP.ClientContext.get_current();
        //var hostcontext = new SP.AppContextSite(currentcontext, hostUrl);
        var webContext = context.get_web();
        var listCreationInfo = new SP.ListCreationInformation();
        listCreationInfo.set_title(listName);
        listCreationInfo.set_customSchemaXml(listxml)
        var newList = webContext.get_lists().add(listCreationInfo);
        context.load(newList);
        context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        function onQuerySucceeded() {
            alert(oList.get_title() + ' created successfully.');
        }
        function onQueryFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
    },
    error: function (error) {
        console.log(error);
    }
    });

}

but failed to create list, I got this error:

Cannot read property 'apply' of undefined

Is it possible to create list using schema XML in JavaScript? Suggest some help?

0

change this line:

context.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

to

context.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
  • it sovle above error but gave another error: Invalid list template – Mrunal Shidurkar Aug 7 '16 at 16:50

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.