Why is my Google App Script running itself without triggers? - google-apps-script

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.

Related

Google sheets importhtml refresh error management

I have a spreadsheet that imports from various websites 10 tables using importhtml. I have a refresh script which helps me to update that data every 30 minutes. This is working fine. My problem is that plenty of times one or more of the importhtml fails which has as result all the cells that are using the data i am importing to give wrong results. Is there any way to keep the data I had taken earlier from importhtml if there is an error at refreshing?
maybe not what you need, but try to wrap your imports into 1-2 IFERRORs like:
=IFERROR(IMPORTHTML(...); IMPORTHTML(...))
or:
=IFERROR(IFERROR(IMPORTHTML(...); IMPORTHTML(...)); IMPORTHTML(...))
this way if some importing error occurs the IFERROR will re-try it. it may help in some cases - ofc not always.

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.

showColumns(n,n) previously worked but no longer works

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.

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.

Refresh Button / Auto Update GOOGLE SPREADSHEET

I hope you can help me. I have been trying to get this working for quite some time.
I am taking the API from a website import it into google spreadsheets VIA importjson()
ImportJSON("http://api.796.com/v3/futures/ticker.html?type=weekly")
https://gist.github.com/chrislkeller/5719258
I have no problem importing the json data into google spreadsheet, now the hard part is making the data update, I would really like it to auto update but even a "update now" button would be great.
Thanks,
This has been driving me nuts.
BV
So I was searching for a good way to do this as well. Here is what I have found so far.
If you change the function line of the importJSON like this:
function ImportJSON(url, query, parseOptions, recalc) {
}
Which just adds the recalc parameter to the function definition. This is a 'trick' because that parameter is not used for anything other than to make GSheet think something has changed.
Then in the call to ImportJSON (in a GSheet cell), you add in the function call like this:
=ImportJSON("https://yourDomain.com/something","","rawHeaders",A1)
Then in the sheet you can manually change the value of A1 to anything different than it is. The Sheet and all the imports will get refreshed.
Another ... non-technical trick ... manually change A1 to 1 then 2 then 3. Each time the sheet will recalc. Now you can use the UNDO and REDO buttons to change the numbers and recalc the sheet.
A little of a kludge Hack, but it does make for a one-button "recalc" of a sort.
You can just add the time trigger
https://developers.google.com/apps-script/understanding_triggers
File > Spreadsheet settings > Calculation > Recalculation: On change and every minute
Then you can insert a =now() column and it will refresh the sheet every minute.
Apologies if you've tried this already, I have it setup now in a sheet but am waiting for a live event to test, so it might not even work.
Im not really a javascript person, but I might have a little code that might help start you off. (Sorry if it does not help). What I use in my site is this (I changed it a little bit to incorporate your url).
$( document ).ready(function($) {
setInterval(function(){
$('.sell').load('http://api.796.com/v3/futures/ticker.html?type=weekly');
}, 5000);
});
This just grabs the JSON every 5 seconds, so be sure you parse the JSON and display the data you need. Hope this helps! :)