Issue with Google Script not initializing in a second form

I'm currently working on a project that is bound to a Google Sheet container. The purpose of this project is to search for a specific value in one column, and based on the result, either mark the record as complete, allow for missing values to be filled in, or add a new row if the value doesn't exist.

The HTML implementation is not posing any challenges, and with the help of Stackdriver Logger, I've confirmed that the initial form values are being passed correctly. These values include setting a cache which determines the content of the second HTML form for the sidebar. However, upon submitting either of the second forms, the function intended to add values to the table is not initializing, despite using the same script.

Here's a snippet from the <script> tags within the initial HTML file:

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

This excerpt shows the script included 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);
      };
      // More onchange events...
      document.querySelector("#noCUNYID").addEventListener("submit", 
      function(e) {
        e.preventDefault();
        google.script.run.noCUNYIDSubmit(this);
        google.script.host.close();  
      }
      );

And here's an example from the sub-level forms:

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

Despite the expected behavior of google.script.run calling the functions, there seems to be an issue where Stackdriver does not show the function opening, although google.script.host.close() executes properly. Any insights into what might be causing this problem would be greatly appreciated.

Answer №1

There is a high probability that the script is ending before the script.run finishes its execution.

To resolve this issue, make sure to utilize the withSuccessHandler callback in order to execute the close function when the script has completed.

    google.script.withSuccessHandler(function() {
       google.script.host.close();
    }).run.yesCUNYIDSubmit(this);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Performing Jasmine unit testing on a component that relies on data from a service, which itself retrieves data from another service within an Angular 2+ application

Attempting to implement unit testing for a service using httpmock has been challenging. The service in question utilizes a method to make http get calls, but I have encountered difficulties in writing the test cases. saveservice.service.ts -- file const ...

Error message thrown on the login page: "Attempting to access property 'push' of an undefined object"

I'm currently working on a login page using JWT and I'm facing an issue with trying to redirect the user to the home page after successful login. I am using this.props.history.push("/") for redirection but I keep getting an error: TypeError: Cann ...

The 'onChange' event in React is being triggered only once

Currently utilizing material-ui Library Below is my React component: import Checkbox from '@material-ui/core/Checkbox'; import FormControlLabel from '@material-ui/core/FormControlLabel'; import React from "react"; import { withStyles ...

Tips for adjusting the size of an imported item in Three.js?

Currently, I am utilizing Three.js for my project and I am importing .OBJ file using OBJ LOADER () Everything has been working smoothly thus far, but I have come across an issue that has me stumped. I am trying to figure out how to change the width and he ...

Alter the class of the div element every three seconds

Greetings, I trust everyone is doing well. I am in need of some assistance from your brilliant minds. I have a circular div along with three CSS classes, and my objective is to switch the div's class and update the label text every 3 seconds. Any insi ...

I am unable to display the content even after setting `display: block` using the `.show()`

Hello there, I have attached my javascript and html code. While in debug mode, I can see that the CSS property 'display: none' changes to 'display: block', but for some reason, the popupEventForm does not open up. Any suggestions on why ...

Performing web scraping on a page rendered with Javascript in Python 3.5

I'm currently working on a project that involves extracting a dynamically rendered table using Python 3 and a webdriver. Below is the code I have implemented: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait fro ...

HTML: Determine the Precise Location of a Div Element That is Centered

Imagine I have this image: Is there a way for me to determine the x/y or left/top properties of my canvas if it is centered using the following CSS: #canvas-container { width: 100px; height:100px; margin: 0px auto; } Note ...

Refresh ng-repeat following data entry or push in Angular Material dialog

Currently, I am facing an issue with adding a new object to an ng-repeat array. The array is populated with data fetched through an $http request. My goal is to input data in a dialog and pass it to a function that will then add the data as an object to th ...

Tips for incorporating a CSS transition when closing a details tag:

After reviewing these two questions: How To Add CSS3 Transition With HTML5 details/summary tag reveal? How to make <'details'> drop down on mouse hover Here's a new question for you! Issue I am trying to create an animation when t ...

Unable to retrieve data from the array

I am encountering an issue while trying to fetch data from an array, as I keep receiving undefined Please refer to the image for a visual representation of my problem. I'm not sure what I might be overlooking, so any help would be greatly appreciate ...

Utilizing the `theme` property in makeStyles with Material-UI

I am currently working on passing down an muiTheme to a component through the use of ThemeProvider, and I also want to apply it to the children components. Furthermore, I aim to utilize the theme's properties in both components by creating a classes o ...

Utilize angularjs daterangepicker to refine and sift through data

I am currently utilizing the ng-bs-daterangepicker plugin by ng-bs-daterangepicker and encountering difficulty in filtering when selecting a start date and end date. Below is a snippet of my code: <input type="daterange" ng-model="dates" ranges="range ...

Discovering the worth of objects in a MongoDB array - a guide

I need assistance to access the value of a nested object within an array. I have the _id of the parent object and the _id of the child object in the array, but I am struggling to get the value of "solvedOn" in order to toggle a checkbox behavior. Here is ...

Preparing the format/serialization of a JQuery JSON array prior to submitting it

Looking at the JSON structure I have: { "firstArrayOfJSON": [ { "something" : "something" }, { "another" : "another" }, { "secondArrayOfJson" : [ ...

VueJS together with Firebase: The guide to password validation

I am currently working on a web form developed using VueJS that enables authenticated users to modify their passwords. The backend system relies on Firebase, and I am facing a challenge in validating the user's current password before initiating the p ...

Is there a way to compel Google Maps to load within my Angular application by implementing an Angular Directive?

I am encountering an issue where my Google Map fails to display most of the time. It seems that the map is not fully rendered when the rest of my data is populated in my Angular view. Is there a way to force the map to load? I have done some research and ...

Executing an AJAX POST request from one domain (localhost:9393) to another domain (localhost:9696) using Spring Rest

I am encountering an issue with a form on one app running on localhost:9393. The JavaScript function used to post data is: function registerClient() { var postData = $("#client-reg").serializeArray(); var formURL = "http://localhost:9393/mPaws/client/re ...

A beginner's guide to using Jasmine to test $http requests in AngularJS

I'm struggling with testing the data received from an $http request in my controller as I don't have much experience with Angular. Whenever I try to access $scope, it always comes back as undefined. Additionally, fetching the data from the test ...

Having trouble with res.render() when making an axios request?

I am encountering an issue with my axios requests. I have two requests set up: one to retrieve data from the API and another to send this data to a view route. const response = await axios({ method: 'POST', url: 'http:// ...