TypeError: Cannot read property “values” from undefined. (line 2, file “Code”)
I had a sendEmails function that worked, but now it there is a bug.
I get this error:
TypeError: Cannot read property "values" from undefined. (line 2, file
"Code")
I have a simple form that has 3 columns (including the form timestamp) - Section A and Section B. I added a trigger to run the script when a new line is added to the form. I use the same script for a bunch of other things, but now for some reason it is not working.
function sendEmails(formResponse) {
var answers = formResponse.values;
var SectionA = answers [1];
var SectionB = answers [2];
var html = "<html><strong>Section A: </strong>"+ SectionA + "<html><strong><br />Section B: </strong>" + SectionB;
var range = formResponse.range;
var row = range.getRow();
var column = range.getLastColumn();
try {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: SectionA,
htmlBody: html,
});
} catch (e) {
console.error("Did not send email to " + Sponsor + ". See error: " + e);
range.getSheet().getRange(row, 3).setValue("EMAIL NOT SENT");
return;
}
range.getSheet().getRange(row, 3).setValue("EMAIL SENT");
}
google-apps-script google-form
add a comment |
I had a sendEmails function that worked, but now it there is a bug.
I get this error:
TypeError: Cannot read property "values" from undefined. (line 2, file
"Code")
I have a simple form that has 3 columns (including the form timestamp) - Section A and Section B. I added a trigger to run the script when a new line is added to the form. I use the same script for a bunch of other things, but now for some reason it is not working.
function sendEmails(formResponse) {
var answers = formResponse.values;
var SectionA = answers [1];
var SectionB = answers [2];
var html = "<html><strong>Section A: </strong>"+ SectionA + "<html><strong><br />Section B: </strong>" + SectionB;
var range = formResponse.range;
var row = range.getRow();
var column = range.getLastColumn();
try {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: SectionA,
htmlBody: html,
});
} catch (e) {
console.error("Did not send email to " + Sponsor + ". See error: " + e);
range.getSheet().getRange(row, 3).setValue("EMAIL NOT SENT");
return;
}
range.getSheet().getRange(row, 3).setValue("EMAIL SENT");
}
google-apps-script google-form
1
What is this form? Are you working in Google Sheets, or working with Google Forms? And what kind of object isFormResponse
?
– Dustin Michels
Nov 20 at 19:08
The function is running, so the trigger must still be installed. But, you might try deleting the trigger and installing it again. The event object will be null if you run the code from the code editor, but if an event is triggering the function to run then it should be passing an event object. Which makes me think that it could be a bug.
– Sandy Good
Nov 20 at 19:34
The question is unclear as it doesn't include enough details and because it's using wrong terms like "simple form that has 3 columns" (forms have questions not columns but it looks that should say "simple sheet" instead of "simple form").
– Rubén
Nov 21 at 22:58
add a comment |
I had a sendEmails function that worked, but now it there is a bug.
I get this error:
TypeError: Cannot read property "values" from undefined. (line 2, file
"Code")
I have a simple form that has 3 columns (including the form timestamp) - Section A and Section B. I added a trigger to run the script when a new line is added to the form. I use the same script for a bunch of other things, but now for some reason it is not working.
function sendEmails(formResponse) {
var answers = formResponse.values;
var SectionA = answers [1];
var SectionB = answers [2];
var html = "<html><strong>Section A: </strong>"+ SectionA + "<html><strong><br />Section B: </strong>" + SectionB;
var range = formResponse.range;
var row = range.getRow();
var column = range.getLastColumn();
try {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: SectionA,
htmlBody: html,
});
} catch (e) {
console.error("Did not send email to " + Sponsor + ". See error: " + e);
range.getSheet().getRange(row, 3).setValue("EMAIL NOT SENT");
return;
}
range.getSheet().getRange(row, 3).setValue("EMAIL SENT");
}
google-apps-script google-form
I had a sendEmails function that worked, but now it there is a bug.
I get this error:
TypeError: Cannot read property "values" from undefined. (line 2, file
"Code")
I have a simple form that has 3 columns (including the form timestamp) - Section A and Section B. I added a trigger to run the script when a new line is added to the form. I use the same script for a bunch of other things, but now for some reason it is not working.
function sendEmails(formResponse) {
var answers = formResponse.values;
var SectionA = answers [1];
var SectionB = answers [2];
var html = "<html><strong>Section A: </strong>"+ SectionA + "<html><strong><br />Section B: </strong>" + SectionB;
var range = formResponse.range;
var row = range.getRow();
var column = range.getLastColumn();
try {
MailApp.sendEmail({
to: 'email@gmail.com',
subject: SectionA,
htmlBody: html,
});
} catch (e) {
console.error("Did not send email to " + Sponsor + ". See error: " + e);
range.getSheet().getRange(row, 3).setValue("EMAIL NOT SENT");
return;
}
range.getSheet().getRange(row, 3).setValue("EMAIL SENT");
}
google-apps-script google-form
google-apps-script google-form
edited Nov 21 at 0:32
TheMaster
9,3203731
9,3203731
asked Nov 20 at 18:56
Ed Santos
1
1
1
What is this form? Are you working in Google Sheets, or working with Google Forms? And what kind of object isFormResponse
?
– Dustin Michels
Nov 20 at 19:08
The function is running, so the trigger must still be installed. But, you might try deleting the trigger and installing it again. The event object will be null if you run the code from the code editor, but if an event is triggering the function to run then it should be passing an event object. Which makes me think that it could be a bug.
– Sandy Good
Nov 20 at 19:34
The question is unclear as it doesn't include enough details and because it's using wrong terms like "simple form that has 3 columns" (forms have questions not columns but it looks that should say "simple sheet" instead of "simple form").
– Rubén
Nov 21 at 22:58
add a comment |
1
What is this form? Are you working in Google Sheets, or working with Google Forms? And what kind of object isFormResponse
?
– Dustin Michels
Nov 20 at 19:08
The function is running, so the trigger must still be installed. But, you might try deleting the trigger and installing it again. The event object will be null if you run the code from the code editor, but if an event is triggering the function to run then it should be passing an event object. Which makes me think that it could be a bug.
– Sandy Good
Nov 20 at 19:34
The question is unclear as it doesn't include enough details and because it's using wrong terms like "simple form that has 3 columns" (forms have questions not columns but it looks that should say "simple sheet" instead of "simple form").
– Rubén
Nov 21 at 22:58
1
1
What is this form? Are you working in Google Sheets, or working with Google Forms? And what kind of object is
FormResponse
?– Dustin Michels
Nov 20 at 19:08
What is this form? Are you working in Google Sheets, or working with Google Forms? And what kind of object is
FormResponse
?– Dustin Michels
Nov 20 at 19:08
The function is running, so the trigger must still be installed. But, you might try deleting the trigger and installing it again. The event object will be null if you run the code from the code editor, but if an event is triggering the function to run then it should be passing an event object. Which makes me think that it could be a bug.
– Sandy Good
Nov 20 at 19:34
The function is running, so the trigger must still be installed. But, you might try deleting the trigger and installing it again. The event object will be null if you run the code from the code editor, but if an event is triggering the function to run then it should be passing an event object. Which makes me think that it could be a bug.
– Sandy Good
Nov 20 at 19:34
The question is unclear as it doesn't include enough details and because it's using wrong terms like "simple form that has 3 columns" (forms have questions not columns but it looks that should say "simple sheet" instead of "simple form").
– Rubén
Nov 21 at 22:58
The question is unclear as it doesn't include enough details and because it's using wrong terms like "simple form that has 3 columns" (forms have questions not columns but it looks that should say "simple sheet" instead of "simple form").
– Rubén
Nov 21 at 22:58
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399739%2ftypeerror-cannot-read-property-values-from-undefined-line-2-file-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53399739%2ftypeerror-cannot-read-property-values-from-undefined-line-2-file-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What is this form? Are you working in Google Sheets, or working with Google Forms? And what kind of object is
FormResponse
?– Dustin Michels
Nov 20 at 19:08
The function is running, so the trigger must still be installed. But, you might try deleting the trigger and installing it again. The event object will be null if you run the code from the code editor, but if an event is triggering the function to run then it should be passing an event object. Which makes me think that it could be a bug.
– Sandy Good
Nov 20 at 19:34
The question is unclear as it doesn't include enough details and because it's using wrong terms like "simple form that has 3 columns" (forms have questions not columns but it looks that should say "simple sheet" instead of "simple form").
– Rubén
Nov 21 at 22:58