0

I have a script that takes input from a JDBC connection and writes it to a worksheet. There are times that the result of this operation is not what was expected, so I have spread code like this at key points in the script:

          Logger.log("Trying to delete rows, received: "
                      +  e.message) ;
              Logger.log("   Continuing.") ;

When I run such code from the script editor's RUN button, I can see the latest execution log without effort - it's right there in front of me. But when I run the same code from a menu created like this:

function onOpen() {
    var menuItems ;
    var spreadsheet = SpreadsheetApp.getActive();
    var user = Session.getEffectiveUser().getEmail() ;
    var validUsers = [ validUsersList ]

    if (spreadsheet.getDataRange().canEdit()) {
        menuItems = [
            {name: 'Process all streams' , functionName: 'processAllStreams'}
            , {name: 'Build covered artists'           , functionName: 'rebuildCoversSheet'}
            //, {name: 'Add to song list'              , functionName: 'buildSongList'}
            //, {name: 'Process selective streams'       , functionName: 'processStreams'}
            //, {name: 'Move suggestions to top'         , functionName: 'moveSuggestionsToTop'}
            , {name: 'Go to bottom'                    , functionName: 'showBottomRange'}
            , {name: 'New livestream details'          , functionName: 'getNewLivestreamDetails'}
                ];
        spreadsheet.addMenu('Process it', menuItems);

             etc.

When run from that menu, I do not see the log. I have gone to the editor and checked there; it does not seem to know about scripts that were run outside of the development environment.

What must I do in order to see these logs? I realize that there is a cloud logging option but it looks like it's not such simple setup. And the docs don't say anything about limitations of running scripts via menu or via the script editor. The documentation does mention some limitations:

These logs are intended for simple checks during development and debugging, and do not persist very long.

But they don't seem to address this question. Are there easy approaches?

By the way, running from script editor is not an option for some of the things being done. The reason is that there are prompts and dialogs (getUi.prompt() etc) involved, and those are not allowed from Script Editor mode. So at present it's a catch 22.

EDIT - added a testable script

The following code:

function onOpen() {
    var menuItems = [
            { name: 'Make a log entry', functionName: 'makeEntry' }
        ];
        SpreadsheetApp.getActive().addMenu('Process it', menuItems);
}

function makeEntry() {
  Logger.log('here you go....') ;
}

If you create a new Google Sheet and add this code into the script editor:

Running the script from the script editor, you will see the log entry that gets created.

Running the script from the created ("Process it") menu, I can find no way to find that log entry.

9
  • What do you mean by Execution? Are you referring to the execution log in the upper right of the App Script? You can also check other execution logs in the App Script menu, under Triggers, and then click Executions Commented Feb 4 at 20:28
  • If not, please make a minimal reproducible example that can be copy/paste/run without changes to illustrate the issue. Commented Feb 4 at 20:30
  • @JatsPPG I have added a sample script at the bottom of the question. Thanks for your reply. Commented Feb 4 at 20:53
  • 1
    Thanks for sending a sample video. I see where you went wrong there. You need to click Execution under Triggers, not "Triggers" itself. Commented Feb 4 at 21:29
  • 1
    You're welcome, I'll go ahead and post this as an answer so other people in the community, who may have the same concern as you, will know that theirs can be resolved. Commented Feb 4 at 21:39

1 Answer 1

1

As I mentioned in the comments, you are running the function programmatically with Custom Menu that is why it's not appearing at the upper right execution log.

Here's a simple explanation about it:

If you run the function manually, you can access the execution log in the upper right of the App Script.

Execution at the upper right

Since you are running the function programmatically using Custom Menu, the execution log history can be accessed on the left side of the App Script.

Execution2

The onOpen() trigger automatically runs when a user opens a spreadsheet, document, or presentation, and is typically used to add custom menu options to these Google Workspace apps (as well as Forms).

References:

Sign up to request clarification or add additional context in comments.

2 Comments

Feel free to accept my answer if you feel it was useful to you.
Thanks, this is correct. My code had that onOpen function because I (felt I) needed the menu in order to demonstrate the issue. Great answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.