Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Mostrar el valor en el formulario en tiempo real - secuencia de comandos de la aplicación

Necesito ayuda en el formulario de la aplicación web. Me enfrento al problema de cómo mostrar el valor en tiempo real en el formulario de la aplicación web. acerté con code.gs pero no puedo crear javascript para ejecutar el nivel de intervalo de la función.

Por favor ayúdame con esto.

 function getTime(){ const ss =SpreadsheetApp.getActiveSpreadsheet() const wsData = ss.getSheetByName("Run") const emp = [Session.getActiveUser().getEmail()]; const now = new Date(); const d= wsData.getDataRange().getDisplayValues().reverse(); const emp_i = d.findIndex(r => r[1] === emp.toString()); if (emp_i == -1 && d[emp_i][4] == ""); const hour = new Date(now - new Date(d[emp_i][3])).toISOString().substr(11,8 ); return hour; } var Duration = [getTime()];
 <label for="Duration">Last Activity Duration</label> <select class="w3-select" id="Duration"> <? for(let i=0;i<Duration.length;i++){ ?> <option> <?= Duration[i]; ?> </option> <? }?> </select> </div>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

No veo cómo getTime() devolverá una matriz:

 function getTime() { const ss = SpreadsheetApp.getActiveSpreadsheet() const wsData = ss.getSheetByName("Run") const emp = [Session.getActiveUser().getEmail()]; const now = new Date(); const d = wsData.getDataRange().getDisplayValues().reverse(); const emp_i = d.findIndex(r => r[1] === emp.toString());//emp.toString() doesn't look right if (emp_i == -1 && d[emp_i][4] == "");//I don't think this line is doing anything const hour = new Date(now - new Date(d[emp_i][3])).toISOString().substr(11, 8); return hour; }

pero creo que necesitas un doGet() algo como esto:

 function doGet(e) { const ui = SpreadsheetApp.getUi(); let t = HtmlService.createTemplateFromFile('filename');//create a template t.Duration = getTime(); // assign global variables to the template this way return t.evaluate();//this is htmloutput }

En realidad, es difícil saber qué quieres de tu código. Podría ser mejor simplemente explicar lo que quieres hacer con palabras.

about 4 years ago · Juan Pablo Isaza Report

0

Si desea recuperar la fecha en tiempo real, deberá manejar todo en el lado del cliente y usar el lado del servidor para realizar la solicitud, algo similar a esto:

Código.gs

 function doGet(e) { return HtmlService.createHtmlOutputFromFile('html'); }

html.html

 <!DOCTYPE html> <html> <head> <base target="_top"> </head> <p id="time"></p> <body> <script> var timeDisplay = document.getElementById("time"); function getTime() { var dateString = new Date().toLocaleString("ZONE", {timeZone: "YOUR_TIMEZONE"}); var formattedString = dateString.replace(", ", " - "); timeDisplay.innerHTML = formattedString; } setInterval(getTime, 1000); </script> </body> </html>

Sin embargo, si simplemente desea llamar a la función desde el código de Apps Script, debe actualizar su código del lado del cliente a esto:

 <script> for (let i = 0; i < length; i++) { google.script.run.getTime(); } </script>

La comunicación con las funciones de Apps Script se realiza mediante google.script.run . Esta es una API JavaScript asincrónica del lado del cliente que permite que las páginas de servicios HTML llamen a las funciones del lado del servidor.

Referencia

  • Aplicaciones Web de secuencias de comandos ;

  • Comunicarse con las funciones del servidor .

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!