Skip to content Skip to sidebar Skip to footer

Uncaught Typeerror: Google.script.run.dosomething Is Not A Function

I am trying to check if the input name is already in a Google Sheet. However, I am getting this error: Uncaught TypeError: google.script.run.doSomething is not a function. Here

Solution 1:

How about this modification?

Issue of your script:

  • doSomething() of google.script.run.doSomething() is required to be Google Apps Script.
    • In your script, doSomething() is put in HTML (index.html), and a method for using Google Apps Script is included. When google.script.run.doSomething() is run, doSomething() cannot be found at Google Apps Script (code.gs). By this, such error occurs. And if doSomething() is run at HTML side, also an error occurs at Sheets.Spreadsheets.Values.get(), because Sheets.Spreadsheets.Values.get() is the method of Advanced Google Services with Google Apps Script.
  • If you put it to Google Apps Script (code.gs), Javascript which is used at the script of doSomething() is required to be modified.

Modified script:

In this modification, your script was separated to Google Apps Script (code.gs) and HTML (index.html). var nameGiven = document.getElementById("meetingTitle").value; and checkNameCS(name); are used in index.html.

By the way, before you run this script, please enable Sheets API at Advanced Google Services.

Google Apps Script: code.gs
functionstrip(str) {
  return str.replace(/^\s+|\s+$/g, '');
}

functiondoSomething (nameGiven) {
  var nameExists = false;
  var nameVerified = false;
  var name = nameGiven.toLowerCase();
  name = strip(name);

  var spreadsheetId = '###'; //Sheet id enteredvar rangeName = 'Sheet1';
  var values = Sheets.Spreadsheets.Values.get(spreadsheetId, rangeName).values;
  if (values) {
      for (var row = 0; row < values.length; row++) {
          if (name == values[row][0]) {
              nameExists = true;
          }
      }
  }

  if (nameExists) {
      return"";
  }

  nameVerified = true;
  return name;
}
HTML: index.html
<!DOCTYPE html><html><head><basetarget="_top"><metacharset="UTF-8"></head><body><inputtype="text"id="meetingTitle"value=""><buttononclick="checkName()">Check if available</button><pid=nameVerification><i>Click the button above to check availability.</i></p><script>functioncheckName() {
            var toPass = document.getElementById("meetingTitle").value;
            prompt("toPass " + toPass);
            var nameGiven = document.getElementById("meetingTitle").value; // Added
            google.script.run.withSuccessHandler(checkNameCS).doSomething(nameGiven); // Modified
        }

        functioncheckNameCS(checkNameSSReturn) {
          console.log(checkNameSSReturn)
            if (checkNameSSReturn == "") {
                document.getElementById('nameVerification').innerHTML = "Already in Use: Please try with another name."document.getElementById("meetingTitle").value = "";
            } else {
                document.getElementById("meetingTitle").value = checkNameSSReturn;
                document.getElementById('nameVerification').innerHTML = "Meeting name available. Procced."
            }
        }
    </script></body></html>

Reference:

Post a Comment for "Uncaught Typeerror: Google.script.run.dosomething Is Not A Function"