Why is my OnChange trigger triggering multiple times? I have created this code to generate a pdf and email it. To run it automatically I have created an OnChange trigger. It runs good however executes multiple times. Please help...
function emailPoaAsPDF() {
var ss =SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1xEEEiLfil1qfetSwZRhr02Q9uoXvWtCxq22JywTu5mo/edit#gid=1872480652").getSheetByName("POA Temp");
var email = ss.getRange("a37").getValue();
var cc_email = "xxxxxx@gmail.com";
var name = ss.getRange("a34").getValue();
var sub = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx of "+ name;
var body = "Hello "+ name + ","
+ "xxxxxxxxxxxxxxxxxxxx"
var url='https://docs.google.com/spreadsheets/d/1xEEEiLfil1qfetSwZRhr02Q9uoXvWtCxq22JywTu5mo/export?';
var exportOptions =
'exportFormat=pdf&format=pdf' +
'&size=a4' +
'&scale=2' +
'&top_margin=1' +
'&bottom_margin=1' +
'&left_margin=1.25' +
'&right_margin=1.25' +
'&portrait=true' +
'&fitw=false' +
'&sheetnames=false&printtitle=false' +
'&pagenumbers=false&gridlines=false' +
'&fzr=false' +
'&gid=1872480652';
var params = {method:"GET",headers:{"authorization":"Bearer "+
ScriptApp.getOAuthToken()}};
var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();
GmailApp.sendEmail(email, sub, body, {
htmlBody: body,
cc: cc_email,
attachments: [{
fileName: "xxx for " + ss.getRange("a34").getValue().toString() +".pdf",
content: response.getBytes(),
mimeType: "application/pdf"
}]
});
var nameFile = ss.getRange("e7").getValue().toString() + " for " +
ss.getRange("a7").getValue().toString() +".pdf"