Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

logic - How to convert Google Forms answers to boolean variables to lead to a certain page

First time using Stack Overflow so excuse me if I'm doing this wrong

I'm doing a school project and I want to make a google form with 8 different yes or no questions that lead to a specific page depending on the combination of answers. I used truth tables and logic to find what combinations of answers lead to what results. For example, the logic expression A'B'E'F ( C' + D ) leads to a result about cable trays for cable management. However, I'm trying to find a way to actually do this.

I was wondering if anyone knows if it's possible to use Google's Apps Scripts to do this. I'm just looking for a way to turn a yes/no answer in a form into a true/false variable that can be used to send to a specific page.

I'm trying to do it in google forms but am open to other sites.

question from:https://stackoverflow.com/questions/65944040/how-to-convert-google-forms-answers-to-boolean-variables-to-lead-to-a-certain-pa

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Opening an URL from a form submission is not possible in Apps Script because during form submission, the form editor is not open.

Based on Class Ui:

A script can only interact with the UI for the current instance of an open editor, and only if the script is container-bound to the editor.

One workaround I could suggest is to send an email to the respondent with the url link.


Sample Form:

enter image description here

enter image description here

enter image description here

  • Each Yes or No multiple choice question is set to required.
  • Collect email addresses is enabled under Forms Settings
  • Custom confirmation message was set under Forms Settings "Please check your email for the reference link"

Forms Script Editor:

Sample Code:

function onSubmitForm(e) {
 
  var response = e.response;
  //Get item responses
  var items =response.getItemResponses();
  //Get respondent's email
  var email = response.getRespondentEmail();
  var url;
  var A = [];

  //Convert responses Yes/No to 1/0
  for(var i = 0; i<items.length; i++){
    A.push(items[i].getResponse()=="Yes"?1:0);
  }
  Logger.log(A);

  Logger.log(!A[0] * !A[1] * !A[4] * A[5] * (!A[2] + A[3]));

  //Check if logical expression was satisfied A'B'E'F ( C' + D )
  if(!A[0] * !A[1] * !A[4] * A[5] * (!A[2] + A[3])){
    url = "https://www.youtube.com/?hl=en&gl=PH";
  }else{
    url = "https://google.com";
  }

  //Send Email with the link
  var subject = "Test Email";
  var body = "Please refer to this link: "+url;
  MailApp.sendEmail(email,subject,body);

}

Sample Trigger Configuration:

enter image description here


Output:

enter image description here

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...