0
votes

I have a sheet (spreadsheet b) that data gets sent to from a source sheet (spreadsheet a) using a submit button generated by a script.

Spreadsheet b uses this code to then copy this data automatically to another spreadsheet (spreadsheet c):

function onChange() {

var sourceSpreadsheet = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Albany");
var sourceData = sourceSpreadsheet.getRange("A1:E39").getValues();
var targetSpreadsheet = SpreadsheetApp.openById("1NRhJ-
g6s8i05XVsAZDepJlWTB1zLuiKwS7zxp66QWJE").getSheetByName("Albany");

targetSpreadsheet.getRange("A1:E39").setValues(sourceData);
}

This code works if a physical edit has been made to spreadsheet b, but does not work when the data has been sent to spreadsheet b from spreadsheet a using the submit button. How can I get this to work?

(Note: I can't seem to have spreadsheet a go straight to spreadsheet c because the editors using spreadsheet a are not shared with spreadsheet c.)

I can't use the importrange function because edits might have to be made to the data on spreadsheet c.

2

2 Answers

0
votes

These are the only types of changes detected by onChange: EDIT, INSERT_ROW, INSERT_COLUMN, REMOVE_ROW, REMOVE_COLUMN, INSERT_GRID, REMOVE_GRID, FORMAT Link

Perhaps you can wrap the current actions into the original function run by the submit button.

0
votes

Short answer

Include all the actions on script that its called by the button.

Explanation

From https://developers.google.com/apps-script/guides/triggers/events

The various Google Sheets-specific triggers let scripts respond to a user's actions in a spreadsheet.

The above means that an onchange event will not be triggered by a change made by a script.