skip to Main Content

My project is on Google Apps Script. I’ve been working on writing an html dialogue for a dropdown menu. I was having issues with getting my secondary function to run, and I’ve whittled down the issue with google.script.run.

When I run function custdialogue, the menu pops up as expected, and I get the alert with the selected value as expected. On my executions tab, I can see each instance of custdialogue that I test, but no executions for logval.

Is this a formatting error?

JS:

function custdialogue() {
  const htmlDlg = HtmlService.createHtmlOutputFromFile('Filename')
      .setSandboxMode(HtmlService.SandboxMode.IFRAME)
      .setWidth(200)
      .setHeight(150);
  const ui =SpreadsheetApp.getUi()
  ui.showModalDialog(htmlDlg, 'Title');
};

function logval() {
  console.log("value")
}

HTML:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <label for="option-list">Pick an option:</label>
      <select option="option-list" id="option-list">
        <option value="one">One</option>
        <option value="two">Two</option>
        <option value="three">Three</option>
        </select>
        <button id="button" onclick="submitval()">Click</button>
        <input type="submit" id="button" value="close" onclick="closeIt()"/>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
    </script>
    <script>
      function submitval(){
        var entry = $(document.getElementById('option-list')).val()
        alert(entry)
        closeIt()
        
      }
      function closeIt(){
        google.script.host.close()
      }
      
      googe.script.run.withSuccessHandler(submitval)
        .logval();
     

    </script>
   
  </body>
</html>

Currently, I am expecting to see an execution for custdialogue and an execution for logval. Upon opening the execution for logval, I would see that the console logged "Value".

When I run this function, I only see an execution for custdialogue

2

Answers


  1. It appears you have a typo in your code.

    Replace

    googe.script.run.withSuccessHandler(submitval)
            .logval();
    

    With

    google.script.run.withSuccessHandler(submitval)
            .logval();
    
    Login or Signup to reply.
  2. Try it this way:

    gs:

    function custdialogue() {
      const htmlDlg = HtmlService.createHtmlOutputFromFile('ah2').setWidth(200).setHeight(150);
      SpreadsheetApp.getUi().showModelessDialog(htmlDlg, 'Title');
    };
    
    function logval(v) {
      Logger.log(v);
    }
    

    html:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <base target="_top">
    </head>
    <body>
          <select id="option-list">
            <option value="" selected></option>
            <option value="one">One</option>
            <option value="two">Two</option>
            <option value="three">Three</option>
            </select>
            <input type="button" value="close" onclick="myfunk();">
        <script>
          function myfunk() {
            google.script.run.withSuccessHandler(() => {
              google.script.host.close();
            }).logval(document.getElementById("option-list").value);
          }
        </script>
    </body>
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search