Specifying form for 'on form submit' trigger

后端 未结 3 2010
面向向阳花
面向向阳花 2020-12-04 03:08

I have two google forms, which send data to two tabs in a single spreadsheet.

I have set up a script with two functions. I would like the first function to run on s

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 03:21

    As I suggested in the comments, you can determine the origin of the form submission by analyzing the response object's content.

    Here is a basic example to illustrate : it will send you an email to tell which form has been submitted but you can of course use the same condition test to select the action you want to run.

    function formSubmitOriginTest(e){
    //  Logger.log(JSON.stringify(e));
    // example value : {"namedValues":{"Untitled Question 2":["test"],"Timestamp":["8/17/2014 11:22:47"]},"values":["8/17/2014 11:22:47","test"],"source":{},"range":{"rowStart":3,"rowEnd":3,"columnEnd":2,"columnStart":1},"authMode":{}}
      if(e.namedValues["Untitled Question 2"]!=undefined){// only form B has one question with this exact title, that's enough to identify it.
        MailApp.sendEmail(Session.getActiveUser().getEmail(),'form B has been submitted','');// optionally include the answers in the email body if you want
      }else{
        MailApp.sendEmail(Session.getActiveUser().getEmail(),'form A has been submitted','');// optionally include the answers in the email body if you want
      }
    }
    

提交回复
热议问题