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

404
Views
¿Cómo puedo usar la variable en el archivo gs como valor de entrada en el archivo HTML en el script de Google Apps?

La variable fieldName para la función testGetFieldName se encuentra en Code.gs

Quiero insertarlo en el valor de entrada del archivo index.html.

Pero si abro Sidebar usando testSetValue, el valor aparece como no definido.

¿Cómo puedo hacer que la variable 'Cuenta' salga con Valor?

El código que escribí es el siguiente.

 //code.gs function testGetFieldName(){ var fieldName = 'Account'; return fieldName; } function testSetValue(){ var html = HtmlService.createTemplateFromFile('index'); var output = html.evaluate() .setTitle('MySidebar') .setWidth(400) .setSandboxMode(HtmlService.SandboxMode.IFRAME); SpreadsheetApp.getUi().showSidebar(output); }

índice.html

 <!DOCTYPE html> <html> <head> <base target="_top"> </head> <body> <input type="text" id ='textValue' name='textValue' value=''/> <script> document.getElementById('textValue').setAttribute('value',google.script.run.testGetFieldName()); </script> </body> </html>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

En su guión, ¿qué tal la siguiente modificación?

Lado de Google Apps Script:

De:

 var html = HtmlService.createTemplateFromFile('index'); var output = html.evaluate()

A:

 var html = HtmlService.createTemplateFromFile('index'); html.value = testGetFieldName(); var output = html.evaluate()

Lado HTML:

De:

 document.getElementById('textValue').setAttribute('value',google.script.run.testGetFieldName());

A:

 document.getElementById('textValue').setAttribute('value', '<?= value ?>');

Nota:

  • Si desea utilizar google.script.run , ¿qué tal la siguiente modificación?

    • De

       document.getElementById('textValue').setAttribute('value',google.script.run.testGetFieldName());
    • A

       google.script.run.withSuccessHandler(e => { document.getElementById('textValue').setAttribute('value', e); }).testGetFieldName();

Referencia:

  • Servicio HTML: HTML con plantilla
about 4 years ago · Santiago Trujillo 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!