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.

  • Try with survey instead of Survey – Gautam Sheth May 12 '17 at 8:14
  • @GautamSheth Thanks, I tried both but still it's throwing an same error – Debugger May 12 '17 at 8:20
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());
        }   
| improve this answer | |
  • @Suriya have you tried this?let me know if you face any issues. – SynozeN Technologies May 12 '17 at 11:51
0

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
            })
        );
| improve this answer | |
  • How does that solve the issue mentioned in question? – Akshay Randive Sep 22 at 13:06

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.