0

I am trying to write a container-bound project for a Google Sheet. It would allow me to search for a matching value in one column, and depending on the response, dictate that the record is full, allow me to fill in the missing values, or, if the value is not there at all, write a new row.

The actual HTML isn't an issue, and thanks to Stackdriver Logger, I know that the initial form values are being passed correctly, including setting a value as cache, which is used to decide what is the second HTML form for the sidebar. The thing is that, when I submit either of the second forms, the function I'm attempting to call to add the values to the table are not initializing, even though the script should be the same.

For reference, this is the the contents of the <script> tags in the initial HTML file:

document.querySelector("#cunyID").addEventListener("submit", 
      function(e) {
        e.preventDefault();
        google.script.run.cunyIDQuery(this);
        google.script.run.newSidebar();  
      }
      );

This is the contents of <script> in one of the second forms:

gpa.onchange = function setTwoNumberDecimal(event) {
        this.value = parseFloat(this.value).toFixed(2);
      };
      q1.onchange = function setWholeNumber(event) {
        this.value = parseFloat(this.value).toFixed(0);
      };
      q2.onchange = function setWholeNumber(event) {
        this.value = parseFloat(this.value).toFixed(0);
      };
      q3.onchange = function setWholeNumber(event) {
        this.value = parseFloat(this.value).toFixed(0);
      };
      document.querySelector("#noCUNYID").addEventListener("submit", 
      function(e) {
        e.preventDefault();
        google.script.run.noCUNYIDSubmit(this);
        google.script.host.close();  
      }
      );

And this is from the second of the second-level forms:

q1.onchange = function setWholeNumber(event) {
        this.value = parseFloat(this.value).toFixed(0);
      };
      q2.onchange = function setWholeNumber(event) {
        this.value = parseFloat(this.value).toFixed(0);
      };
      q3.onchange = function setWholeNumber(event) {
        this.value = parseFloat(this.value).toFixed(0);
      };
      document.querySelector("#yesCUNYID").addEventListener("submit", 
      function(e) {
        e.preventDefault();
        google.script.run.yesCUNYIDSubmit(this);
        google.script.host.close();  
      }
      );

Even though, theoretically, google.script.run should be calling for the functions, Stackdriver is not reporting the function opening, and google.script.host.close() is running correctly. Does anyone know what might be going on?

1 Answer 1

3

It is likely that the script is closing before the script.run completes execution.

You should use the withSuccessHandler callback to run close when the script is completed.

    google.script.withSuccessHandler(function() {
       google.script.host.close();
    }).run.yesCUNYIDSubmit(this);
Sign up to request clarification or add additional context in comments.

1 Comment

That definitely fixed that issue, but the function noCUNYIDSubmit now is outputting the error Exception: The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues.at noCUNYIDSubmit(Code:81:71). The array I'm using is definitely right, as console.log was able to output it. Do I need to use a different method to fill the cells? Also, do the cells need to be created beforehand?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.