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 9066353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:42:44+00:00 2026-06-16T16:42:44+00:00

Can anybody see anything wrong in this code // make new ssheet var payablesNewDoc=SpreadsheetApp.getActiveSpreadsheet().copy(newName);

  • 0

Can anybody see anything wrong in this code

  // make new ssheet
  var payablesNewDoc=SpreadsheetApp.getActiveSpreadsheet().copy(newName); // NB  undocumented function

  // Create onEdit trigger for the new Spreadsheet
var onEditTrigger = ScriptApp.newTrigger("onChange")
      .forSpreadsheet(payablesNewDoc)
      .onEdit()
      .create();

  Logger.log(onEditTrigger.getHandlerFunction());  // logs "onChange"
  Logger.log(onEditTrigger.getEventType());        // logs "ON_EDIT"

It runs without error, and the two log messages seem to indicate that the trigger was created. However when I open the new spreadsheet and make an edit, nothing is fired and the script editor doesn’t show any declared triggers.

  • 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-16T16:42:45+00:00Added an answer on June 16, 2026 at 4:42 pm

    because it seems in this instance you are making a copy of the host Sheet and script, the onEdit can be added as a simple trigger within the template script, i.e. a function so defined: function onEdit() { // do stuff }.

    This function will be copied along with the Spreadsheet itself.

    function onEdit() {
      // This function being present will automatically add an onEdit trigger
      // It can act as a parent for calling any other functions
      // e.g. onChange() as per your example
    }
    

    One improvement you could make if you are likely to have many copies of the same script floating about you can call a handler function hosted in a library elsewhere to keep your triggered code in one place. If you attach the external script as a Library with development mode turned on, this Library will also be attached to any copies you make to the original Spreadsheet. This will allow you amend the triggered code without having to open all the copies

    Make a standalone GS script with a handler function that will replicate the functions you originally wished to trigger, you will need to pass the active sheet by Id thusly:

    function editFunction(event) {
      try {
        var range = event.source.getActiveSheet().getActiveSelection();
        return  "cells "      + range.getA1Notation()        + \
               " changed to " + range.getValues().toString() + \
               " in \""       + event.source.getName()       + \
               "\" by "       + Session.getEffectiveUser();
      } catch (err) {
        return err;
      }
    }
    

    then in your template Spreadsheet add the external script as a library (e.g. named EditLibrary).

    within your simple onEdit() function simply call the Library function instead of anything inline; passing event details as a parameter.

    function onEdit() {
      Browser.msgBox(EditLibrary.editFunction(eventObject));
    }
    

    that should do what you need with no need to use the triggerBuilder and allowing you amend your code later.

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

Sidebar

Related Questions

Can anybody see what is wrong with this code. it does not show up
Can anybody see what's wrong with my code? It behaves properly in IE but
Can anybody tell me how are exceptions handled in PHP? I have this code
Does anybody see anything wrong with the following function? ( Edit : no, I
Can anybody please tell me why the removeEventListener call is not working? this.addEventListener(Event.ENTER_FRAME, eventCall,
Can anybody tell me why my Async task fails sometimes like this? I tested
I can't see anything on here but I do remember being told that If
Can anybody give any working example of how to read/write Unicode text files using
Can anybody help me how can I invoke a JSP page from a Servlet
Can anybody show with some examples the exact difference between .. and ... operator?

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.