In the company we have put together a series of interrelated Spreadsheets, where some work as a data entry form, and another acts as a database, where all the information entered is stored.
The data entry templates have the following code outline, made with Apps Scripts:
// Limpiar celdas
function Limpiar() {
var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
var formulario = hojaActiva.getSheetByName("Ingreso Personal");
var celdasALimpiar = ["C3", "C4", "C5", "C6", "C7", "C8", "C11"]; // Celdas a limpiar
for (var i=0; i<celdasALimpiar.length; i++){
formulario.getRange(celdasALimpiar[i]).clearContent();
}
}
// Guardar celdas
function Guardar(){
var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
var formulario = hojaActiva.getSheetByName("Ingreso Personal"); // Nombre de hoja del formulario
var hojaDestino = SpreadsheetApp.openById('1CuP5yRxKrhubZbkb9KrTSJFn5OqyTPzbDi2ixKwJEpY')
var datos = hojaDestino.getSheetByName("F09-Personal"); // Nombre de hoja donde se almacenan datos
// Celdas de donde se obtendrán los datos a guardar
var valores = [[formulario.getRange("C3").getValue(),
formulario.getRange("C4").getValue(),
formulario.getRange("C5").getValue(),
formulario.getRange("C6").getValue(),
formulario.getRange("C7").getValue(),
formulario.getRange("C8").getValue()]];
// Inyección de datos a hoja donde se almacenan datos
datos.getRange(datos.getLastRow()+1,1,1,6).setValues(valores); // El "6" se cambia por cantidad de datos a almacenar
Limpiar(); // Ejecución de función para limpieza de celdas
}
// Buscar
var NUM_COLUMNA_BUSQUEDA = 0;
function Buscar() {
var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
var formulario = hojaActiva.getSheetByName("Ingreso Personal"); // Nombre de hoja del formulario
var valor = formulario.getRange("C11").getValue();
var hojaDestino = SpreadsheetApp.openById('1CuP5yRxKrhubZbkb9KrTSJFn5OqyTPzbDi2ixKwJEpY')
var valores = hojaDestino.getSheetByName("F09-Personal").getDataRange().getValues();
for (var i = 0; i < valores.length; i++) {
var fila = valores[i];
if (fila[NUM_COLUMNA_BUSQUEDA] == valor) {
formulario.getRange("C3").setValue(fila[0]);
formulario.getRange("C4").setValue(fila[1]);
formulario.getRange("C5").setValue(fila[2]);
formulario.getRange("C6").setValue(fila[3]);
formulario.getRange("C7").setValue(fila[4]);
formulario.getRange("C8").setValue(fila[5]);
}
}
}
// Actualizar
function Actualizar(){
var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
var formulario = hojaActiva.getSheetByName("Ingreso Personal"); // Nombre de hoja del formulario
var hojaDestino = SpreadsheetApp.openById('1CuP5yRxKrhubZbkb9KrTSJFn5OqyTPzbDi2ixKwJEpY');
var datos = hojaDestino.getSheetByName("F09-Personal"); // Nombre de hoja donde se almacenan datos
var valor = formulario.getRange("C11").getValue();
var valores = hojaDestino.getSheetByName("F09-Personal").getDataRange().getValues(); // Nombre de hoja donde se almacenan datos
for (var i = 0; i < valores.length; i++) {
var fila = valores[i];
if(fila[NUM_COLUMNA_BUSQUEDA] == valor) {
var INT_R = i+1
var valores1 = [[formulario.getRange("C3").getValue(),
formulario.getRange("C4").getValue(),
formulario.getRange("C5").getValue(),
formulario.getRange("C6").getValue(),
formulario.getRange("C7").getValue(),
formulario.getRange("C8").getValue()]];
datos.getRange(INT_R, 1, 1, 6).setValues(valores1);
SpreadsheetApp.getUi().alert('Datos actualizados');
Limpiar(); // Ejecución de función para limpieza de celdas
}
}
}
// Eliminar
function Eliminar() {
var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
var formulario = hojaActiva.getSheetByName("Ingreso Personal"); // Nombre de hoja del formulario
var hojaDestino = SpreadsheetApp.openById('1CuP5yRxKrhubZbkb9KrTSJFn5OqyTPzbDi2ixKwJEpY')
var datos = hojaDestino.getSheetByName("F09-Personal"); // Nombre de hoja donde se almacenan datos
var interface = SpreadsheetApp.getUi();
var respuesta = interface.alert('¿Está seguro de borrar?',interface.ButtonSet.YES_NO);
// Proceso si el usuario responde
if (respuesta == interface.Button.YES) {
var valor = formulario.getRange("C11").getValue();
var valores = hojaDestino.getSheetByName("F09-Personal").getDataRange().getValues(); // Nombre de hoja donde se almacenan datos
for (var i = 0; i< valores.length; i++) {
var fila = valores[i];
if (fila[NUM_COLUMNA_BUSQUEDA] == valor) {
var INT_R = i+1
datos.deleteRow(INT_R);
Limpiar(); // Ejecución de función para limpieza de celdas
}
}
}
}
Our problem arises with the issue of permissions. The idea is that some of the colleagues can use the data entry forms to enter the information, but that they cannot access the file that works as a database. We originally thought that denying permission to view and edit the database templates would resolve this issue, but when those not authorized to view the database want to use the data entry templates, the following error appears:
You do not have permission to access the requested document
The question is if there is any way to allow the use of the data entry forms, without giving access to the database ones.