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.
Related
I wrote a script months ago and it worked just fine but 2 days ago it stopped placing images. The var name with "url" is misleading seeing I am not using a URL by getting the file by ID.
That part of the script goes is suddenly haywire is:
var icon = finalDisplayArray[i][0]; (Im looping to place the images in this array.)
var iconURL = DriveApp.getFileById(icon);
//Logger.log tells me the above code does give me the valid name of the .jpg file here so it appears Google has the image ready to go
// THE BELOW IS WHERE IT BUGS OUT
ssDisplay.insertImage(iconURL, columnCounter, rowCounter);
// ERROR MSG: Exception: The image could not be inserted. Please verify it is valid and try again.
I haven't been using GAS for that long but is it normal for a program to suddenly quit working like this when it worked fine for months? The "columncounter", etc, is just me placing smaller icons in a row and then columsn if the row gets too long. Thought it might be since I'm using my company's email and the permissions maybe reset but all the file sharing, etc, is what it's always been.
Update: It worked for 5 minutes then stopped working again. Not exactly sure why it's only working part of the time?
This sounds like it's supposed to be simple but I'm only finding information on "getActive" and my function works if I'm using all internal sheets but I tried using openById and nothing happened and openByUrl returns an error. The following is a simplified example of what I'm trying to do:
var store_data_sheet = SpreadsheetApp.openByID('ID here..').getSheetByName('Data');
store_data_sheet.getRange('A1').setValue('testing')
store_data_sheet.insertRows(1);
I'm sure I'm just using the wrong keywords or maybe this isn't even allowed but multiple users will be using their own copy of a specific sheet that runs this function and I'd just like to take certain cell's data and copy it to one external sheet (which is why it also inserts a row so it can push down entries)
Maybe I'm using the wrong "ID"? I assumed the number inside the URL was the ID. If it's something more specific, please let me know.
Like I said, this works flawlessly if I'm referencing an internal sheet. I'd like to be able to do the same exact thing with an external spreadsheet if possible. Thank you!
I found the issue. This function also renames the sheet file so if there is anything in the cell that is used to rename the file, it won't run the storing functions. I either need to run these before the renaming or take out the renaming aspect. ---moving these before the renaming part fixed the problem.
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.
Updated everything to include the ultimate goal of this spreadsheet and the issue I encountered during early testing so that if there's a better way to do this that someone with experience can identify, I can change my approach and do that instead.
Link to copy of sheet here
The Issue:
This macro uses paste special (values only) twice, but it only correctly pastes the first one and does nothing for the second. For example, the the first instance copies data from C6 and pastes only the value to F6, which it does. The second copies from K6 and pastes only the value to M6, which it does not do. Everything else is functioning correctly except for this.
For context, this macro also copies a formula down in between the two copy/paste actions. You'll see the code for that below as well. It's working as intended, so you can ignore that.
With help from below, we identified the issue was that the second paste values only function wasn't working because it was copying the cell before that cell could finish summing its formula.
For example, let's say K6 was =sum(K4+K5) with K4=1 and k5=4. Before the sum could record the answer, "5" in that cell, the copy was grabbing the empty data and pasting it, thus pasting nothing.
I tried setting up a delay using sleep, but it was not a consistent solution. It only works about 50% of the time. If it's possible to set up a delay based around letting a formula finishing its output, that would be a perfect solution. If anyone has experience with a similar issue or suggestions for optimization threads, please link below. I'll loop back if I find a solution.
The Goal and Backstory:
This is a mock-up of an internal tracker we use to gauge our availability (mins) against the project (in mins) to determine roughly when we have the project complete. We use this tracker to determine if something will be late, if we have the availability from our team to take on more projects, etc. It's all manual, and we don't have anyone particularly strong with scripts.
Right now, our solution is to manually enter in our availability in each cell with the assistance of basic sum formulas. This takes a lot of time and is prone to human error. So, I'm trying to find a macro that will do the math for us with my very limited experience in scripts/macros.
In the "The Ideal" tab, I've manually created an example of what I'm ultimately working towards -- a macro that sums and enters in data based on availability vs. project mins. I'm obviously new to this, so there are inevitably inefficiencies and I may be completely on the wrong track. If so, please tell me and offer me an explanation as if you were speaking to a grandparent with basic computer knowledge.
Thanks everyone for your help!
Here's the code:
function TestCalc1() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('D5:H5').activate();
spreadsheet.getActiveRange().autoFill(spreadsheet.getRange('D5:H6'), SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
spreadsheet.getRange('I6').activate();
spreadsheet.getRange('H6').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
spreadsheet.getRange('H6').activate();
};
Try this,
function TestCalc1() {
var spreadsheet = SpreadsheetApp.getActive();
var cellsD5H5 = spreadsheet.getRange("D5:H5").getValues();
spreadsheet.getRange("D6:H6").setValues(cellsD5H5);
var cellH6 = spreadsheet.getRange("H6").getValues();
spreadsheet.getRange("I6").setValues(cellH6);
//spreadsheet.getRange("H6").activate();
};
getValues() -
https://developers.google.com/apps-script/reference/spreadsheet/range#getValues()
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.