Question
How do you edit two different spreadsheets from one connected script that is triggered by an onEdit command?
My Case
I am trying to create a master spreadsheet that sends and deletes information to two other spreadsheets. I have an onEdit function that once a checkbox is checked, it will send specified information to another sheet.
What I've Tried
To open the other spreadsheet I first tried the openByID function but through a little research I don't believe it is possible to edit another spreadsheet through a script that is bound to a spreadsheet. So I created a standalone script (named MasterF) that I deployed as a library to store my function so that I can call it later. I added the library to the master spreadsheet and am using it to call the function but it keeps throwing an error saying, "You do not have permission to call SpreadsheetApp.openById." All of my apps scripts have full permissions to edit, delete, etc. I've also made libraries out of the scripts bound to the other spreadsheets I want to connect and added those libraries to the MasterF library to see if that would help. I still get the same error message when the on edit function, despite trying to use a standalone script. Maybe I missed something, or it is entirely possible that I can't do what I'm trying to do.
Script
This the beginning of the custom function that I created. Essentially when an onEdit function is triggered, data from spreadsheet1 in the "submit" sheet, is transferred to spreadsheet2 in the "dashboard" sheet.
function DataSend() {
var app = SpreadsheetApp;
var ss = app.getActiveSpreadsheet();
var submit = ss.getSheetByName("Submit");
var selldata = submit.getRange('E23:I23').getValues();
//@NotOnlyCurrentDoc
var dash = app.openById(<sheetid>).getSheetByName("Dashboard");
Here's the onEdit Function in the script that is bound to spreadsheet1 (not directly a part of the MasterF library) that triggers the datasend function that is kept in the MasterF library.
function onEdit(e) {
var sheetName = "Submit"
var range = e.range;
if (range.getSheet().getSheetName() == sheetName && range.getA1Notation() == 'K23' && range.isChecked()) {
MasterF.DataSend();
}
}