Hello I am new to the community and I am a novice coder with very little coding experience. I understand some basics and 1st part of the code is working. I am having a problem with the data.foreach(funtion(row) where it is giving a error with brackets and colons
function myFunction() {
var Name = 1;
var Surname = 2;
var AffilliateID = 24;
var emailTemp = HtmlService.createHtmlOutputFromFile("Affiliate email");
}
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Affiliate Responses");
var data = ws.getDataRange("A4:Y" + ws.getLastRow()).getDisplayValues();
data.forEach(function(row) **(**
emailTemp.Name = row[Name]**;**
emailTemp.Surname = row[Surname];
emailTemp.AffilliateID = row[AffiliateID];
))
I have created a var for each line and the tutorial I am following expresses the code as is above. The tutorial may be outdated and some help with an explanation would be appreciated. The bold is the errors.
Thanks
Glenn
3
Answers
Welcome to the community. This seems like a simple syntax issue.
You’re using ( & ) brackets for function braces, when infact they should be { & } (like your first function).
It’s also important that your variables in the right scope. You cannot access the emailTemp variable as it is scoped to your
myFunction
function. I’ve moved this into the global scope for you.Your updated code would look something like this:
For your loop it’s something like that
But to use your
You have to be in the same scope
you need to declare correctly the function that you are passing as a parameter to
forEach
you can also use arrow functions: