I have this code, very simple, made in apps scripts, where I give the parameters so that the information entered is saved in a spreadsheet of the same file.
As an example, I leave a part of the code that I need to modify:
// Guardar celdas
function Guardar(){
var hojaActiva = SpreadsheetApp.getActiveSpreadsheet();
var formulario = hojaActiva.getSheetByName("Ingreso"); // Nombre de hoja del formulario
var datos = hojaActiva.getSheetByName("Prueba"); // 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("C5").getValue(),
formulario.getRange("F5").getValue(),
formulario.getRange("I5").getValue(),
formulario.getRange("L5").getValue(),
formulario.getRange("C8").getValue(),
formulario.getRange("F8").getValue(),
formulario.getRange("I8").getValue(),
formulario.getRange("L8").getValue(),
formulario.getRange("C11").getValue(),
formulario.getRange("F11").getValue(),
formulario.getRange("I11").getValue(),
formulario.getRange("L11").getValue(),
formulario.getRange("C14").getValue(),
formulario.getRange("F14").getValue(),
formulario.getRange("I14").getValue()]];
// Inyección de datos a hoja donde se almacenan datos
datos.getRange(datos.getLastRow()+1,1,1,16).setValues(valores); // El "6" se cambia por cantidad de datos a almacenar
Limpiar(); // Ejecución de función para limpieza de celdas
}
My problem is that now I should save the information that I enter, in a separate file, located in another folder. I'm having a hard time writing the code, since I'm quite new to this tool. Could you give me a hand?
I will give the answer to my problem:
In order to save what was entered in another Sheet, what I did was create a new variable (hojaDestino), and add the Openbyid method, as Ruben told me. The line of code looks exactly like this:
The id is found within the URL of the sheet in question. I'm going to leave the documentation again for more information.
https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app
Finally, in another line, the destination sheet where the data should be printed:
Thanks fredyfx for letting me know what I should do. I will be more attentive to the rules for the next one.