So, the spreadsheet contains multiple functions which run as the editors click on buttons. Some of the functions bring data from other files, which editors don't have access to. So, data are brought into protected ranges. Editors add their inputs into unprotected ranges and as they click on Save, the results are saved back into other files.
Example of how another file is accessed: file: globals.gs
const CAD_PRODUTO = 'XXXXXXXXXXXXxxxxxxxxxxxxxxxx';
const config = {
get ssBDCadProd() {
delete this.ssBDCadProd;
return (this.ssBDCadProd = SpreadsheetApp.openById(CAD_PRODUTO));
}
}
const sheetBDCadProd = config.ssBDCadProd.getSheetByName('CadProduto');
Here's a function using the data from the file above:
//It generates the next item code, based on the last record in the file above
function gerarRef() {
try {
const response = Browser.msgBox('Would you like to confirm it?', Browser.Buttons.YES_NO);
if (response == 'no') {
return;
} else {
let ref = 0;
const refExistentes = sheetBDCadProd.getRange(2, 1, sheetBDCadProd.getLastRow(), 1).getValues();
let ultRef = Math.max(...refExistentes);
Logger.log('Ult.: ' + ultRef)
if (ultRef == 0 || ultRef == '') {
ref = 10000;
} else {
ref += ultRef + 1;
}
const refRng = sheetCadProd.getRange('B5').setValue(ref);
refRng.offset(0, 2).activate();
}
} catch (err) {
Browser.msgBox('The following error has occurred: ' + err);
}
}
I understand that the Web App
approach requires a doGet()
function to be added to it and it's to be deployed with Executed by: Me
and Accessed by: Anyone
.
However, I don't know how to tie it together with the existing functions I got bounded to the spreadsheet.
Appreciate your attention/help!