Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

207
Visualizações
Show the Value on form real time - app script

i need help on the web app form. im faceing issue how to show the value real time on webapp form. i right code.gs but im unbale to create javascript for run the function interval level.

please help me on this.

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 Respostas
Responde à pergunta

0

I don't see how your getTime() is going to return an array:

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;
}

but I think you need a doGet() something like this:

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
}

It's actually hard to tell what you want from your code. It might be better to just explain what you want to do in words.

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want to retrieve the date in real time, you will have to handle everything in the client side and use the server side to make the request, something similar to this:

Code.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>

However, if you'd like to simply call the function from the Apps Script code, you should update your client side code to this:

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

Communicating with the Apps Script functions is done by using google.script.run. This is an asynchronous client-side JavaScript API that allows HTML-service pages to call the server-side functions.

Reference

  • Apps Script Web Apps;

  • Communicate With Server Functions.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda