Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:52:29+00:00 2026-06-04T21:52:29+00:00

I have tried the code examples that I found here on the stackoverfllow site,

  • 0

I have tried the code examples that I found here on the “stackoverfllow” site, related to calling a function from a string. They don’t seem to work in a Google App Script. I receive an error to effect that “window” as an undefined object.

Here is the situation that I am trying to solve.
I have a spreadsheet that is going to have many different
sheets. Some of these sheets will have names that are known
at the time I write the code. Other sheets will have names that are not known
exactly at the time I write the code (e.g. based on dynamic data).

The current documentation tells me that the name of the “onEdit” event
handler is “onEdit”. Since thee name is unique, I conclude that there
can only be one such routine with this name within a spreadsheet application.

Because of this situation (above) I would like reduce the complexity of my
“onEdit” function. I would like to write the “onEdit” routine
to do “dynamic” calls to sub-functions which use qualified names,
based upon the name of the “sheet” in which the edit event occurred.

Here is a pseudo code example of the “onEdit” routine I want to right.

  function onEdit(src)
  {
     var act_sheet = src.getActiveSheet();
     var sheet_name = act_sheet.getName();
     var rtn_name = "onEdit_sheet_".sheet_name;

     if ( function_exists(rtn_name) )
     {
         window[rtn_name](srv)
     }
  }

I have actually tried similar code. In the google environment the “window” object is flagged as an unknown object.

Is there some other “object” name in the environment that I should be using?
Is this possible within the Google Apps Script environment?


In addition, I know that the “function_exists” routine is also a challenge to write.
That will be my next question. I know about the “typeof” operation, it
returns “string” when I code

      "if ( typeof rtn_name == function" ) .. "

Is there a way to test that a routine exists given a name contained in a string?


I know I can use “static” names and hard code them in the “onEdit” routine.
But I would like to write the routine once, and not have to modify it
for each new spreadsheet that I write. In stead of writing very
complicated “onEdit” routines, I want to concentrate on writing
and testing “onEdit” functions for individual sheet’s.

I understand Javascript within a browser environment. The Google apps
script environment is more of a mystery to me. I find the documentation
very very terse, and in need of fuller explanations. Any additional
information about what objects exist in the Google apps script environment
would be helpful.


Of course my third step might be to write an “onEdit” routine that
dispatches the correct sub-function based upon the current “range”
associated with an Edit event.


I am NEW to Google Apps Scripts. I am looking for a script solution.
It probably can be done in “Java”, but that is beyond the scope in which
I want to code.


I am also new to the “stackoverflow” environment. Much of it seems a
mystery to me. (e.g. How do I specify which tags should be associated
with this question? How do I know which tags are available to be assigned
to this question? How do I limit my search to certain tags? – I am
at the moment interested in “google apps scripts”, when I select the
“javascript” button in the right column it takes me into a javascript
answers which may not apply to the google script environment. Found out
how to “assign” tags below. How do I know which tags are available without
just guessing?

All and any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:52:31+00:00Added an answer on June 4, 2026 at 9:52 pm

    I know two ways to call the function using its name on a string in Apps Script.

    function onEdit(e) {
      var func = 'test';
      this[func]();
      //eval(func+'()'); //msgBox and eval don't play nice together
      Browser.msgBox('finished');
    }
    
    function test() {
      Browser.msgBox('test');
    }
    

    Of course, when using the this approach, you should not be in another scope, e.g. from a function called using new. But this exact full code that I’m posting works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this example found here: http://threedubmedia.com/code/event/drag/demo/resize2 and i tried to reproduce it in
I found some fantastic code that meets the needs for my project from here:
I have tried the following code: $('a.buildMenu').click(function (event) { // Prevent normal behaviour event.preventDefault();
I have tried to use the following snippet of code: int main() { string
I have tried to use some of the max length functions found here, but
i have tried this code to redirect a php page.but it s not working
Iam running WAMP server and just enabled php_memcache extension and have tried the code
I have tried the following code but has no effect: Imports system.Runtime.InteropServices <DllImport(UxTheme.DLL, BestFitMapping:=False,
I have tried rectifying the code below. But I am not able to find
I am currently working on Problem 62 I have tried the following code to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.