Reputation: 121
I have an issue with Google Apps Script that should trigger the copy of a range to another Google spreadsheet. The strange thing here is that the script is perfectly working if started through the Script Editor. But it's not working through the trigger (onEdit).
The script itself is much longer and everything related to data processing within one and the same spreadsheet is triggered successfully. Only the copy of a specific range to another spreadsheet is not working. But as I mentioned, it's working if I run it through the Script Editor.
Please see below a simple representation of my script:
function onEdit(e){
var sourceFile1 = SpreadsheetApp.getActiveSpreadsheet();
var sheet = sourceFile1.getActiveSheet();
var selectedRange = sheet.getRange(44,1, 1, 29);
var sourceData = selectedRange.getValues();
var destinationFile = SpreadsheetApp.openById(" ");
var destinationSheet = destinationFile.getSheetByName("Orders");
var lastRow = destinationSheet.getLastRow();
lastRow = lastRow + 1;
destinationSheet.getRange(lastRow, 1, 1, 29).setValues(sourceData);
}
Upvotes: 1
Views: 126
Reputation: 201378
onEdit()
with the script editor, it works.If my understanding is correct, how about this answer?
I think that in your script, when the OnEdit event is run, an error related to the authorization occurs at var destinationFile = SpreadsheetApp.openById(" ");
. When you want to confirm this, please check the execution transcript of script editor after the function is run as the OnEdit trigger.
So as a solution, how about installing the function as the installable Triggers?
onEdit()
as the installable Triggers. But I recommend to modify the function name from onEdit()
to other. For example, it is like installed_onEdit()
.
onEdit()
is run as a simple trigger, when onEdit()
is installed as the installable Triggers, onEdit()
run 2 times as the simple trigger and the installable Triggers.If I misunderstood your question and this was not the solution of your issue, I apologize.
Upvotes: 2