G
G
Grigory Boev2020-02-06 01:11:30
Google Sheets
Grigory Boev, 2020-02-06 01:11:30

How to do bi-directional data sync between Google Spreadsheets?

Good afternoon. Tell me, is there a way to make bidirectional data synchronization between two Google spreadsheets? Those. the user changes the data in the first table - they change in the second. At the same moment, another user can change the same data in the second table and they should change in the first. If it would be read-only, then it would be decided with the help of IMPORTRANGE ()
I did this: I tracked onEdit, opened a book and changed the values ​​​​of the second book to the values ​​\u200b\u200bof the first.

try{
   var rs = SpreadsheetApp.openByUrl(remoteUrl).getSheetByName(remoteListName);
   rs.getRange(row,col,event.range.getValues().length,event.range.getValues()[0].length)
.setValues(event.range.getValues());
   SpreadsheetApp.getActiveSpreadsheet().toast("Данные отправлены!");
}catch(err){
   Browser.msgBox(JSON.stringify(err));
};

As a result, I get an error: insufficient rights. I read it, it seems that onEdit () is truncated in the rights of Editor add-on authorization
{"message":"Вам не разрешено вызывать пользователя SpreadsheetApp.openByUrl. Необходимые разрешения: https://www.googleapis.com/auth/spreadsheets.",
"name":"Exception",
"fileName":"Код",
"lineNumber":60,
"stack":"\tat Код:60 (onEdit)
"}

How to win it? To do the trigger on time? It will turn out unreliable, part of the data may be lost.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question