Search code examples
google-apps-scriptgoogle-sheetsweb-applications

TypeError: this[e.parameter.run] is not a function


This is related to this thread. I don't know what the problem is since I'm just new with this coding thing. But I found the error when I clicked the latest code below the URL.

WebApp

This is the error TypeError: this[e.parameter.run] is not a function (line 2, file "Code").

And, this is the code:

function doGet(e) {
  this[e.parameter.run](e.parameter.sheetName || null); //this is line 2
  return ContentService.createTextOutput();
}

Honestly, I don't know what that function does since I just copy it on this solution. But as far as I understand, it helps for the script to be accessible to other users. What seems to be the problem here?


Solution

  • Explanation

    You function doGet(e) expects a parameter run to which the name of an (existing) function is assigned.

    • This paramter has to be appended to the WebApp URL
    • If you call the WebApp without assigning it any paramater (by pressing on latest code) the function will error
    • Instead, you need to copy the Current web app URL and append to it ?run=NameOfFunction
    • For example: https://script.google.com/macros/s/XXXXXXXX/exec?run=myFunction
    • If your script contains a function called myFunction() - this function will be executed on pasting the full Web App URL including parameter run into the browser address bar.

    Recomendation

    • Modify return ContentService.createTextOutput(); to return ContentService.createTextOutput("It worked");
    • This will give you some feedback about the fact that the Web App has been executed correctly.