Answer the question
In order to leave comments, you need to log in
How to send data from a table as one row to another closed table?
Task: It is
necessary to give managers access to edit their large table, from which, at the click of a button, data enters another table in the form of one line.
The problem is that the manager should not have view permissions on the destination table. And in order for the script to work, the rights to make changes (and, therefore, view) must be.
How can this be resolved?
Here is an example of my script:
var SHEET_ID = '***';
var spreadsheet = SpreadsheetApp.getActive();
var TEST = spreadsheet.getRange("B4").getValue();
var TWO = spreadsheet.getRange("B5").getValue();
var THREE = spreadsheet.getRange("B6").getValue();
var FOUR = spreadsheet.getRange("B7").getValue();
var FIVE = spreadsheet.getRange("B8").getValue();
function myFunction() {
SpreadsheetApp.openById(SHEET_ID).getSheets()[0].appendRow([new Date(), TEST, TWO, FIVE, FOUR, THREE ]);
};
Answer the question
In order to leave comments, you need to log in
Indeed, it is not so obvious the first time, but when you come across, you understand that the user must be an editor in order to make changes. To solve this problem, it is necessary to provide another interface for data entry.
Replace myFunction
with something like:
function recordToMain(){
// Берет диапазон 'Источник!B4:B8' активной Таблицы, т.о. это встроенный скрипт
var data = SpreadsheetApp.getActive().getRange('Источник!B4:B8')
.getValues().map(function(row){return row[0];});
var url = 'https://script.google.com/macros/s/ZZZ/exec';
var options = {
method: 'POST',
headers: {
ContentType: 'application/json'
},
payload: JSON.stringify(data),
muteHttpExceptions: true
};
UrlFetchApp.fetch(url, options);
};
function doPost(e) {
SpreadsheetApp.openById('YYY') // Должна существовать
.getSheetByName('Приемник') // Должен быть лист 'Приемник'
.appendRow([new Date()].concat(JSON.parse(e.postData.contents)));
}
url_master
for the first feature.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question