0

I tried to create a survey list using JSOM

function listCreation () {

    var clientContext = new SP.ClientContext.get_current();
    var oWebsite = clientContext.get_web();

    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title('Test'); // list name
    listCreationInfo.set_description('description'); // list description
    listCreationInfo.set_templateType(SP.ListTemplateType.Survey); //list type

    oWebsite.get_lists().add(listCreationInfo);

    clientContext.executeQueryAsync(
        Function.createDelegate(this, this.onQuerySucceeded),// when success
        Function.createDelegate(this, this.onQueryFailed) // when failed
        );

function onQuerySucceeded() {
    alert("List Created");
}

function onQueryFailed(sender, args) {
    alert("List Failed");
}
}

while executing the function it throws an error msg Uncaught Error: Sys.ArgumentUndefinedException: Value cannot be undefined. in clientContext.executeQueryAsync line. Please help me to solve this issue.

2
  • Try with survey instead of Survey May 12, 2017 at 8:14
  • @GautamSheth Thanks, I tried both but still it's throwing an same error
    – Debugger
    May 12, 2017 at 8:20

2 Answers 2

1

Following code is working for me for creating survey list, and it is 'SP.ListTemplateType.survey'

        function CreateCustomList() {
            clientContext = new SP.ClientContext.get_current();
            oWeb = clientContext.get_web();
            listCreationInfo = new SP.ListCreationInformation();
            listCreationInfo.set_title('Test Custom List Survey');
            listCreationInfo.set_templateType(SP.ListTemplateType.survey);
            oList = oWeb.get_lists().add(listCreationInfo);
            clientContext.load(oList);
            clientContext.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());
        }   
1
  • @Suriya have you tried this?let me know if you face any issues. May 12, 2017 at 11:51
1

The post is very old, But if anyone facing this issue can write the inline function at delegate to resolve the issue.

clientContext.executeQueryAsync(
            Function.createDelegate(this, function() {
               //On success
  
            }),
            Function.createDelegate(this, function() {
              //on failed
            })
        );
1
  • How does that solve the issue mentioned in question? Sep 22, 2020 at 13:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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