Help with Google Apps Script (Google Forms)

Job ID: 36241780

Budget: €12 – €18 EUR

I need your help to fix my Google Apps Script.
It is not working.

I have set up the trigger, but onFormSubmit(e) is not called.

If you see the error(s), please send me a message.

Thank you!

function myfunction() {
var form = FormApp.create('PSSD / PSF survey');

// Add problems question with "Other" option
var problemsQuestion = form.addMultipleChoiceItem()
.setTitle('Problems')
.setChoiceValues(['Libido','Anesth', 'brain fog'])
.showOtherOption(true);

// Add gender question on a new page
var genderQuestion = form.addPageBreakItem()
.setTitle('Gender')
.setGoToPage(FormApp.PageNavigationType.CONTINUE)
.addMultipleChoiceItem()
.setTitle('What is your gender?')
.setChoices([
form.createChoice('Male'),
form.createChoice('Female'),
form.createChoice('Other')
])
.setRequired(true);

// Log the published URL of the form
Logger.log('Published URL: ' + form.getPublishedUrl());
}

function onFormSubmit(e) {
var form = FormApp.getActiveForm();
var formResponse = e.response;
var itemResponses = formResponse.getItemResponses();

for (var i = 0; i < itemResponses.length; i++) {
var itemResponse = itemResponses[i];
var question = itemResponse.getItem().getTitle();
var answer = itemResponse.getResponse();

// Ask "why did you choose answer" for all questions except gender confirmation
if (question !== 'Are you sure that you are a <gender>?') {
var followupQuestion = form.addPageBreakItem()
.setTitle('Follow-up question')
.setGoToPage(FormApp.PageNavigationType.CONTINUE)
.addParagraphTextItem()
.setTitle('Why did you choose ' + answer + '?');
}

// Add gender confirmation question on a new page
if (question === 'What is your gender?' && answer !== 'Other') {
var confirmationQuestion = form.addPageBreakItem()
.setTitle('Gender confirmation')
.setGoToPage(FormApp.PageNavigationType.CONTINUE)
.addMultipleChoiceItem()
.setTitle('Are you sure that you are a ' + answer + '?')
.setChoices([
form.createChoice('Yes'),
form.createChoice('No')
])
.setRequired(true);
}
}
}
Related categories: JavaScript Google Chrome Google APIs