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

206
Views
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 answers
Answer question

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 Report

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 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!