I am trying to create a script where if you change the values in Column D from blank to "Create Something", it will launch a google form.
I tried this code, but nothing happens. Also edited the trigger button, but nothing happens.
function onEdit(e) {
var sheet = e.source.getSheetByName('Sheet1'); // Replace 'YourSheetName' with the actual name of your sheet
var columnDIndex = 15; // Column D is the 4th column (1-indexed)
if (e.range.getColumn() == columnDIndex && e.value == 'Create Something') {
openGoogleForm();
}
}
function openGoogleForm() {
var formUrl = 'https://docs.google.com/forms/d/yourid'; // Replace 'your-form-id' with the actual ID of your form
var form = FormApp.openByUrl(formUrl);
form.createResponse().submit();
}
I believe your goal is as follows.
Create Somethingis put into column "D" of "Sheet1", you want to open Google Form.Modification points:
var columnDIndex = 15; // Column D is the 4th column (1-indexed)ande.range.getColumn() == columnDIndexmean column "O".e.value == 'Create Something', when a value ofCreate Somethingis put by copying and pasting, the value ofe.valuehas no value. Please be careful about this.When these points are reflected in a sample script, it becomes as follows.
Sample script:
Please copy and paste the following script to the script editor of Google Spreadsheet and save the script. And, please install the OnEdit trigger to the function
installedOnEdit. RefAnd, please set your Google Form URL to
formUrl.And, please confirm your sheet name. In this sample, when a value of
Create Somethingis put into column "D" of "Sheet1", the script works. Please be careful about this.When you put a value of
Create Somethinginto column "D" of "Sheet1", a Google Form is opened.In this sample, in order to open Google Form, Javascript is used on a dialog.
In this sample, the Google Form of the public URL is opened. If you want to directly open Google Form please modify the above script as follows.
If you don't want to check the sheet name, please remove
sheet.getSheetName() == "Sheet1" &&.References:
Added:
From your provided Spreadsheet, I noticed that your value of
var formUrl = 'https://docs.google.com/forms/d/yourid';is the public URL. From your script, I thought that this URL might be the URL for editing.In this case, it is required to use my 2nd script. But, from your situation, I'm worried about the installable trigger. So, I added one more sample script including your URL. Please confirm it.
Please replace your current script with the following script.
Please directly run
installOnEditTrigger()with the script editor. By this, the installable OnEdit trigger is installed to the functioninstalledOnEdit.Please edit a cell of column "D" of "Sheet1". By this, the script is automatically run by the installable OnEdit trigger.