Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Use Markdown for this comment
Set severity, which reflects how much the issue affects the use of the product
Change issue status back to 'Assigned'
Pending code changes (auto-populated)
[ID: 1388909]
[ID: 1388852]
[ID: 1388884]
0: low
5: moderate
10: good [ID: 1388853]
[ID: 84481]
processed = processed by automation
triaged = validated by human
blocked = depends on another issue
information_requested = depends on reporter supplying additional information
unblocked = the issue is no longer blocked, but may not be fixed
fixed = a change was submitted but may not be deployed fully [ID: 1245093]
[ID: 1388836]
[ID: 1385984]
Set the version(s) of the product affected by this issue (comma-separated list)
Set the version(s) of the product in which the issue should be fixed (comma-separated list)
Set the version(s) of the product in which the issue fix was verified (comma-separated list)
Set if this issue occurs in production
Tags used for linking issues. [ID: 1172495]
Set Reporter
Set Type
Set priority, which reflects how soon the issue should be fixed
Set Status
Set Assignee
Set Verifier
Remove item
View or edit staffing
View issue level access limits(Press Alt + Right arrow for more information)
Description
Before opening a new issue, please search for other related issues , click the ★ to subscribe to updates, and click
+1
to vote.Description
EL PRESENTE CÓDIGO GENERA ERROR INTERNO, NO APARECE INFORMACIÓN RELACIONADA AL RESPECTO. SOLO NECESITO SOLUCIONAR EL ERROR PARA ESTE Y LOS DEMÁS PROYECTOS QUE HE REALIZADO, AUNQUE REQUIERA PAGAR. AGRADEZCO SU AYUDA.
ID DE APP SCRIPT: 1to6UaQap4h4y7iOXTPye-ObgXNx3IX1jxPe9UolocZjN9cYCTpkNQB99
Code
function copySheet() { let idSheet = "1Sp9pi652EM98CJACpKVpXtquRjiPGXMcLI7w6p9OLwc";//ID HOJA const libro = SpreadsheetApp.openById(idSheet); const hojadatos = libro.getSheetByName("Respuestas de formulario 1"); const hojadestino = libro.getSheetByName("Control"); let lastrow_datos = hojadatos.getLastRow(); let lastrow_destino = hojadestino.getLastRow(); Logger.log("LastRowData: " + lastrow_datos); Logger.log("LastRowDestinity: " + lastrow_destino); let valdata = hojadatos.getRange("B" + lastrow_datos + ":C" + lastrow_datos).getDisplayValues(); Logger.log(valdata); const narry = valdata.flat().filter(Boolean); Logger.log(narry); hojadestino.appendRow(narry); hojadestino.getRange("C2:D2").copyTo(hojadestino.getRange("C" + (lastrow_destino + 1) + ":D" + (lastrow_destino + 1))); combinarDocumentoxFila(); }
//=================== FUNCIONES AUXILIARES ============================================================================== function fecha() { var fecha = Utilities.formatDate(new Date(), "GMT-05:00", "dd-MM-yyyy"); Logger.log(fecha); return fecha; }
//=================== COMBINAR CORRESPONDENCIA/DOCUMENTOS x FILA =============================================================== function combinarDocumentoxFila() { var id = "1EOpbKOemLd9Pe7nTY1lXzGSSyjm9mMnGczuIE4V1fIU";//obtiene si id para usarlo y mas adelante generar una copia var folder = DriveApp.getFolderById('1R2hIv7CyWj_vZGKs9KiyRowj66a53yRP'); //ID del folder docs sincronizado con GDrive.
var creaCopia = DriveApp.getFileById(id).makeCopy(nom() + "-" + fecha(), folder); // crea la copia del doc var idCopia = creaCopia.getId(); //obtiene el id de la copia var copiaDoc = DocumentApp.openById(idCopia); //abre la copia para poder ser editada
var copia = copiaDoc.getBody(); //obtiene el contenido del body copia.replaceText("<codebar>", codebar()); //remplaza etiquetas por el dato copia.replaceText("<Nombre_Completo>", nom()); //remplaza etiquetas por el dato copia.replaceText("<Documento_Identidad>", doc_id()); //remplaza etiquetas por el dato copiaDoc.saveAndClose(); //guarda cambios y cierra el archivo 0> equivale a flush en Google sheets. var pdf = folder.createFile(copiaDoc.getAs('application/pdf'));//crea el pdf DriveApp.getFileById(idCopia).setTrashed(true) //elimina el doc y deja el PDF.
}
//=================== FUNCIÓN OBTENER LISTA POR ÚLTIMA FILA =================================================================
function codebar() { var codebar1 = Math.random() * 1542008; var codebar2 = Math.floor(Math.random() * (codebar1 + 1684)).toFixed(0); var codebar3 = Math.random() * 1631997; var codebar4 = Math.floor(Math.random() * (codebar2 + 2576)).toFixed(0); var code = codebar2 + codebar4; Logger.log(code); return code; }
function nom() { var hoja = SpreadsheetApp.openById('1Sp9pi652EM98CJACpKVpXtquRjiPGXMcLI7w6p9OLwc').getSheetByName("Control"); var lastrow = hoja.getLastRow(); let valnom = hoja.getRange("C" + lastrow).getDisplayValues(); let nombre_completo = valnom[valnom.length - 1].toString(); Logger.log(nombre_completo); return nombre_completo; }
function doc_id() { var hoja = SpreadsheetApp.openById('1Sp9pi652EM98CJACpKVpXtquRjiPGXMcLI7w6p9OLwc').getSheetByName("Control"); var lastrow = hoja.getLastRow(); let valdoc_id = hoja.getRange("D" + lastrow).getDisplayValues(); let documento_identidad = valdoc_id[valdoc_id.length - 1].toString(); Logger.log(documento_identidad); return documento_identidad; }
Output
23 feb 2024, 13:44:55 Información LastRowData: 48 23 feb 2024, 13:44:55 Información LastRowDestinity: 47 23 feb 2024, 13:44:55 Información [[ Juan Esteban Barrientos López, 1040750795]] 23 feb 2024, 13:44:55 Información [ Juan Esteban Barrientos López, 1040750795] 23 feb 2024, 13:44:56 Información Juan Esteban Barrientos López 23 feb 2024, 13:44:56 Información 23-02-2024 23 feb 2024, 13:45:00 Información 7488312894244286 23 feb 2024, 13:45:00 Información Juan Esteban Barrientos López 23 feb 2024, 13:45:00 Información 1040750795
Steps