Home > Software engineering >  AppScript onOpen not working. Log shows it triggers but no output, etc
AppScript onOpen not working. Log shows it triggers but no output, etc

Time:08-19

I've been trying this for some time. What I'd like to do is upon sheet opening, copy a value from one cell to another. Seems simple enough. My latest iteration is this. (apologies in advance if I had made a typo, I'm hand transposing it from a different system). What I put below applies to either closing and opening the sheet or running the function via Apps Script interface.

    function onOpen(e) {
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Settings').getRange(2,6).setValue(SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Home').getRange(7,5).getValue())
    }

Nothing happens. If I look in Executions log I can see onOpen triggered, without errors. If I put a Logger.log("Hello") in the function onOpen the execution log will not show the logged 'Hello'. If I put Logger.log("Hello") or Logger.log(SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Home').getRange(7,5).getValue()) in any other function and run it - I will see 'Hello' or the value in the Home sheet.

Any thoughts?

CodePudding user response:

Posting my answer from the comments for future references:

Google Apps Script sometimes fails temporarily for a couple of minutes, so I would recommend creating a new script file, then paste the same code, delete the old one and try again.

This is a very common "behavior"/"bug" from Google Apps Script as somehow it gets "stuck" for a short period of time and I have heard from a lot of people that has had the same experience. I would recommend reporting this in Google's issue tracker showing your results to see if this can get fixed.

References:

  • Related