O
O
OpenReligion2019-01-21 12:37:31
Google Sheets
OpenReligion, 2019-01-21 12:37:31

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

1 answer(s)
A
Alexander Ivanov, 2019-01-21
@oshliaer

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 myFunctionwith 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); 
};

Also create a new script project, in which create a function like:
function doPost(e) {
  SpreadsheetApp.openById('YYY') // Должна существовать
  .getSheetByName('Приемник')    // Должен быть лист 'Приемник'
  .appendRow([new Date()].concat(JSON.parse(e.postData.contents)));
}

When you publish a new project to everyone on behalf of yourself, you will receive url_masterfor the first feature.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question