showColumns(n,n) previously worked but no longer works - google-apps-script

The script below has been working for a several years,but has very recently stopped working properly. I can't figure out why.
In my CLASSROLL sheet, the email column 14 is normally hidden.
The desired behaviour of this script is to show a column for a period of time then hide it again.
The actual behaviour is that script runs for the expected period the column doesnt show.
Diagnosistic action to date.
-Running Debug shows nothing.
-Manually unhiding column 14 and then running the script shows that the hideColumns does work at the last stage of the script.
Can anyone help with this please? Why has it stopped working only recently?
function showEmails(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("CLASSROLL");
sheet.showColumns(14,1);
Utilities.sleep(20000);
sheet.hideColumns(14,1);
}

Resolved: Script needed SpreadsheetApp.flush(); after the line sheet.showColumns(14,1);
no explanation as to why this flush has become necessary only recently.

Related

Script suddenly stops working but works in other sheets

Been using getFileById & insertImage in a sheet/program for months with no problem but it suddenly stopped working two days ago. In order to solve the issue I created a fresh sheet and did this simple code:
function myFunction() {
var picId = "1x2jkgSQvVKAIOg6DQ0rss82YhTQl918c";
var picToPlace = DriveApp.getFileById(picId);
SpreadsheetApp.getActiveSpreadsheet().insertImage(picToPlace,1,1);
}
It works just like it should however if I stick the same code into my main sheet I get "Exception: The image could not be inserted. Please verify it is valid and try again."
Why is this happening? I'm not doing anything different, the function is sitting by itself. Been building this sheet/program for months. Have I overloaded the sheet somehow? Again, if I make a fresh, plain sheet, stick this code in it, it works fine, but if I go back to my main sheet, stick in the same function, it just refuses to work. Its in its own function, nothing else is happening w/in it, it's the only thing I'm calling. I'm at a lost trying to figure out why insertImage has completely stopped working in this sheet. There are thousands and thousands lines of code, over 15K rows of data in some tabs, it's referencing hundreds and hundreds of pictures I've uploaded to a server, and processing various aspects of thousands of people I've inputted into this program. Did I overload this sheet somehow or is Google just over me right now (ie, does it not like me trying to use insertImage, for example, 100 times in one call..) Sorry, I've put so much effort into this and the "insertImage" function suddenly not working is a major blow to it when it is NOT the code that is malfunctioning. If it was the code at least I could fix it.
What's odd is I was running the program 2 days ago. Would look up, for example, 100 people and then have it show me all the pics on one page. Ran this a few times and in the middle one of the outputs it suddenly stopped working. I re-ran a query, asked it to show me pictures and it started placing like 20 of them and then just refused to show any more at all. This really seems like Google telling me to f8ck off.

Suddenly moveActiveSheet returns an error - Google Apps Script

I am getting the following error:
Exception: Service Spreadsheets failed while accessing document with
id . . .
when I try to execute a script on a Google sheet.
The script worked fine until today.
I believe the problem occurs between these two lines:
var newTab = sheet.duplicateActiveSheet();
sheet.moveActiveSheet(1);
because at the time of the error the duplicate sheet has been created
but has not yet been moved to the first position.
Is it possible that the "moveActiveSheet" command suddenly can not
find the new active sheet that has just been created?
If so, is there some other way to do this?
There seems to be a bug and it has already been reported.
The issue has been already reported today (15th of December) in the IssueTracker by 13 users (as of now).
Click on the star ⭐ icon to the top/upper-left corner of the webpage to make the issue more popular in order for Google to fix it sooner.
This workaround solution might be useful, I haven't tested it, but you can give it a try.
The problem is an internal error in the moveActiveSheet line.
I have found a work around for the problem.
In the script comment out the moveActiveSheet line as shown here:
var newTab = sheet.duplicateActiveSheet();
// sheet.moveActiveSheet(1);
sheet.renameActiveSheet(newTabName);
This will result in the new tab being misplaced.
You can manually move it to the first position.
Google claims to be working on a fix for this problem.
See https://issuetracker.google.com/issues/175625775
The bug occurs when pos in sheet.moveActiveSheet(pos) is 1
While the bug is being fixed, as a workaround, instead of e.g. moving the second sheet to the first position, you can move the first sheet to the second position.
Because
sheet.moveActiveSheet(2);
still works.

sheets add-on giving 1-hr trigger error, even when there are no triggers installed

I wrote my first google app script with simple menu & sidebar; it works fine from script-editor but when I publish it as a 'sheets add-on' then
1. one of the textbox's in sidebar is missing
2. sidebar's submit/cancel buttons are not working
Further more, on executing other menu items ... I keep on getting "the recurrence interval for an add-on trigger must be at least one hour". Yes, I had installed 10 mins triggers before, but now I have removed them all ... just to make the 'add-on' work cleanly. I also renamed onOpen(), but no respite.
I am stuck, dont know what to try next ? Any help will be greatly appreciated.

Why is my Google App Script running itself without triggers?

I have a short 1 line script to generate a random integer so I can set it up to run with a trigger so that every time an integer is generated my other scripts using it as a reference will update instead of using a cached version.
The problem is it seems to be running by itself without triggers about once every 10 minutes or so and I don't know what is causing it.
This is the code:
function RandomInt()
{
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Player List").getRange('B1').setValue(Math.random());
}
It works perfectly except the part about it running by itself.
Edit:
So far I believe I have found out that triggers are per user (I did not know this and couldn't find anything about it, but it might just be common sense) So someone else may have a trigger set up for it because a decent amount of people use the sheet.
I ran the deleteTriggers() script Craig posted at Unable to delete triggers (google-apps-script)
And have not noticed the script running by itself anymore. The value has been the same for the last 30 minutes instead of changing every 10.
Edit2: It seems it was alright at first it stopped updating itself but when I added a trigger to update once per hour it started updating it randomly at approximately every 10 minute intervals again.
Edit3: I have abandoned trying to figure out what is wrong and decided to do
function Update()
{
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Player List").getRange('B1').setValue(new Date().getUTCHours());
}
This instead it works well with triggers and even if you set it to shorter intervals it doesn't change the value until the next hour.
Edit4: I have confirmed that the problem was created by someone elses triggers running to every 10 minutes, so the script should work fine, not sure how to close this.

getRangeByName stopped working! Document corrupted or known issue?

As referenced here (https://code.google.com/p/google-apps-script-issues/issues/detail?id=2589), calling getRangeByName stopped working on documents that were perfectly working until now. Is this a known issue? How to fix this? I've seen reports about people complaining about the "instability" of this method that would stop working at time. This is a problem for us as we are using this extensively to populate company dashboards!
Thanks for your ideas
try
SheetName!rangename
i.e. add the sheet name to your named range. I was setting this with code, not sure if it works from the UI. When I switched to this way, my problems with named ranges went away.
Background:
With only one sheet, all worked fine, but having a few sheets caused problems. I think it was caused when I duplicated sheets with names ranges in. Adding the sheet name solved the problem. Also deleting all the named ranges and adding them again solved the problem.