I have a trigger that I can't find! At least, I can't find it easily, and may have to resort to the brute force method.
I've got more than a hundred scripts and spreadsheets-with-scripts, and somewhere in there I have a function called colorRows that is set up as a trigger. I know that, because it shows up in my triggers list:
How can I find the script that contains colorRows?
I've tried using Search in Google Drive, but it appears to be unable to find the content of scripts contained in spreadsheets. (It does index standalone scripts, so that did narrow down my search to just spreadsheets.)
I can open every spreadsheet, then open the script, and search - brute force. No thank you, that's still some 75 sheets.
Script Services getProjectTriggers() is project-based, as the name implies, and only works within the project it's running in.
The title of Spreadsheet source of a programmed trigger sounded good, but is quite different.
I don't want to stop the trigger (that's easy), I want to find the code. So How to Stop Orphaned Triggers is irrelevant.
There is a record of this complaint, Issue 146. It was raised in July 2010, and closed as Won't Fix in Feb 2011.
Related
I’ve created a Google Sheet – kind of like an app – using script. It’s a number of blank cells where once added some information, it creates a string with that information in the right order. I created this to help some colleagues. We are using free accounts.
I face 2 problems:
The app is supposed to be used by only one person at a time, but I’m sure at some point two or more people will want to use it at the same time. Is there a way to allow this without they interfering with each other? I’ve read you can share a link that creates copies of your doc, but that wouldn’t work in this case because I intend to keep updating it regularly.
The changes people make to the sheet will stay there. Right now I have a onOpen function that just rewrites everything, but if someone accesses the document while someone is using it they’ll rewrite everything and ruin their work.
Any ideas on how to solve these two problems? Thank you so much in advance!
I think that you have to find another way to implement your "app" because Google Sheets not a good tool for limiting that only one user edit a spreadsheet a time, but if for any reason you decide to keep with it,...
... you need to implement a workflow like the following
Save the active user email on PropertiesService.getUserProperties().
This should be done by each user by running a script themselves. The most user-friendly will be by using a macro, custom menu or button (a drawing with an assigned Google Apps Script function). You might use an open installable trigger to validate that the active user have already done this.
You might have to make the function that clears the data a "smart" function.
You might have to consider additional cases, like if the owner of the spreadsheet opens it when there is an editor working on the spreadsheet.
Use installable triggers to manage the sharing settings.
Use an open trigger to remove all the editors except the active user
Use a time-driven trigger to add again the editors. To make this work effectively should define how the time-driven trigger will know that the last editor have finished their session, i.e. you might use DriveApp.getFileById(SpreadsheetApp.getActiveSpreadsheet().getId()).getLastUpdated()
The above should help you with both problems, as long you as the owner do not open the spreadsheet as is used by someone else.
Other alternatives that might work better is to create an add-on or a web application.
Related
Determine current user in Apps Script
Last modified date in Google App Script GAS sheets
I have 50 google sheet files for 50 students. They need to key in their answers in their own google sheet file when they are asked to do so. I have a main google sheet to consolidate their data by using IMPORTRANGE formula. This is my formula:
=QUERY({IMPORTRANGE(...);IMPORTRANGE(...);IMPORTRANGE(...);...},"Select * where Col1 is not null")
I will have 50 IMPORTRANGE in the formula. So as expected, the main google sheet is very lag when the 50 students start to key in their answers at the same time. Sometimes, the formula will show #Value when all the students started to answer the questions at their own google sheet file. I need to keep refreshing the main google sheet so that the data will come out, but it will disappear again in a short while then I need to refresh it again (although it will settle down once most of the students finished answering the questions).
I know that using IMPORTRANGE is really not an efficient way to consolidate their answers in main google sheet file but I don't have other better way.
I tried to write a script so that they can send in their data by clicking the button assigned with the script. However, all the students need to go through the authorization process when they run the script for the first time. They don't know how to proceed when they saw the authorization process (not very good in using computer).
May I know is there any ways or tricks that I can use to solve the IMPORTRANGE issue? Or there are some way to write the script where we are not required to go through the authorization process when we run the script for the first time?
Hope to get some advice and help on this as I couldn't find a better way from Google already. Any help will be greatly appreciated!
If I understood correctly what you are looking is that your spreadsheet show in real-time the data being entered simultaneously on 50 different spreadsheets. I'm afraid that Google Sheets is not the right tool for what you are trying to do the way that you are trying to do it. Basically you have two options : change it or use a different tool.
It's not a good idea to have and array of multiple IMPORTRANGE functions that are being edited simultaneously because while the official docs says that IMPORTRANGE functions are updated every 30 minutes when the source and the spreadsheet having formula are opened at the same time the import is done practically immediately and could happen multiple times during the recalculation making causing it to start over an over again.
Replacing the above array by script might help only if you are open to not have the destination spreadsheet updated on real time as scripts are slow.
Replacing the above array by a program that uses the Google Sheets API also might help only if you are open to not have the destination spreadsheet updated on real time as the spreadsheet refresh.
Regarding running a script without requiring authorization that is only possible when using simple triggers and / or removing all the scopes that require authorization to run. Please bear in mind that you might create installable triggers to run other using the authorization of the user who creates them.
Related
Combining multiple spreadsheets in one using IMPORTRANGE
Why do two users sometimes see different values from importrange?
Multiple IMPORTRANGE
Using that many IMPORTRANGE formulas is definitely a bad idea. What I'd suggest you to do:
keep a list of all your student spreadsheet in your main document
write a script that will browse through all of the spreadsheets from that list and copy/paste values into your main document
create a time based trigger that will run the script every X minutes (or hours), depending on how accurate you want the results to be
This is a simple solution, but efficient. Depending on the amount of data and number of students/spreadsheets you may consider other solutions (like writing a cloud function that will do the same as the script) but I think this will work for your use case
There is a Google sheet with a bound Apps script. One of the functions (written by me some time ago) that applies custom formatting etc. is triggered by an installed onEdit trigger (installed by the client). This worked perfectly until now.
The spreadsheet owner (one of my clients) recently complained that when he enters any text into a cell then the cell next to it will automatically get overwritten with "FALSE", and when he edits that "FALSE" then the first cell gets overwritten with "FALSE", which makes no sense at all.
I have checked the original script, which still looks fine, it can not cause this automatic mess creation. To make sure I am not missing something, I have checked, there is only one installed trigger, and there is no other simple onEdit function in the bound script.
I have also temporarily changed the name of the function started by the installed onEdit trigger to disable the trigger. Despite the fact that now editing could not run any function in the bound script, the automatic mess was still active, and something has automatically overwritten some cells when the user is editing.
This makes me suspect that an external unbound script (could be also a script bound to another spreadsheet with a timer trigger) might be the culprit and doing all the mess.
My question is whether or not there is a way to identify any external scripts (not bound to this spreadsheet) that change the sheets?
In this case I can not provide any code or show you the spreadsheet/script because it is confidential, belongs to the client. I can not show you any code that I have tried either. Only the above explanation how I attempted to locate the source of the problem.
Additionally let me add, that in this case more than one people are messing with the sheets and scripts in the background that I don't know who they are. Therefore, there is a chance that some rogue parties are trying to deliberately sabotage my work (if for nothing else, then as a prank).
UPDATE_1
I have made a copy of the spreadsheet, then verified the installed triggers page and there are no triggers installed.
Next, to make absolutely sure that none of my scripts should cause the problem, I have deleted all my scripts. Only an empty project remained, still having the same name as originally. Saved the empty project. Reloaded the spreadsheet and tested again.
The problem still exists: when I edit the misbehaving cells, the cell next to it automatically changes to "FALSE".
I have also made sure that no ARRAYFORMULA is present in those columns.
The right answer to the topic question was first given here by #TheAddonDepot thanks, but for some reason he deleted it. If he re-posts the same answer here, I will accept it as the best answer and give full credit for it. Then few minutes later Rafa Guillermo repeated it as seen above.
The answer is that it is not possible to identify external apps that modify the spreadsheet, but the only chance to find a trace is to look into the version history to see which editors have modified the sheets. I take this as the correct answer as long as someone does not offer a better answer.
In mean time (as explained in the update of the original post) I have stripped down all scripts from the spreadsheet, but the problem was still present. With this setup the only remaining suspects were any addons.
It turned out that there were these two addons visible in the Add-ons menu but they were not installed:
Sheets2GCal
Magic Cell Notifications
Since I could not remove an addon that was not installed, I had to install Sheets2GCal and then removed it right away. This fixed the problem, the automatic mess has stopped.
But, to make sure the other one should not cause any problems in the future, I have installed and uninstalled that one as well.
Thanks again to the contributors.
I have a script that runs on a Google Sheets that is fed by a Forms entry. Basically, when I fill out a form, it creates an entry on the sheet. From that entry, a new document is created by my script that "prettifies" the fields on the sheet for distribution.
This sheet is located on a Team Drive, but in order to have the resulting document created in my drive, I had to place the unbounded script in my drive and reference the sheet. If I have it bounded to the sheet, it will always put the newly created document in the Team Drive -- which I don't want.
When it was bounded to the sheet, I had a trigger that would automatically create the document when the form was submitted. Now that the script is on my drive, triggering on submission is not an option. The only options I have are time based or calendar based, and neither of these really work -- unless I only want to get the document once a month or every single minute.
So now, the only way I know to execute the script is to do it manually every time, which is a major hassle and requires multiple steps no matter how you go about it.
Is there a way to trigger this script on command without having to open the Script editor, click the script I want, and then click run?
Why are there no keyboard shortcuts in Apps? I know about Ctrl+R -- but this only works if you already have the script you want highlighted in the top action bar. If I type Ctrl+R without it already highlighted, nothing happens. Nothing happens with Alt+R or Alt anything, really. I have tried simply tabbing 187 times to get to where I need, but the tab never seems to focus "in" the script menu area. It just bounces around the address bar, the shortcuts bar, etc.
NOTE: I do not want to make major changes to THIS script. It took forever to get this working right and I don't want to jack it up. I just want to be able to trigger it without having to go through 18 steps to do so.
There is no way to execute a standalone script project's function with a keyboard shortcut from within the Apps Script Editor. If your script was bound, you would have the option of keyboard shortcuts from the container Google Sheets file (as a google-sheets-macro), but macros have some restrictions.
However, you are not without options. Two of them:
Publish the script project as a webapp and use a page visit as the trigger.
Open the page / click a bookmark -> execute the function via your doGet().
Convert your script to a 'polling' style that processes any number of form responses, and use a time-based trigger (e.g. hourly, daily) to automate the whole process.
(Include a "did I process this response yet" flag to prevent reprocessing a response)
There are more elaborate configurations (e.g. Apps Script API + local cron job) but those are unlikely to be simpler than the above two options.
As I mentioned in my comment, you more than likely just needed an extra step for the original bound script to create the file in your Google Drive and not the host Team Drive. If you're interested in that avenue, you'll want to ask the appropriate (read: new) question.
This is a workaround not an answer.
I use the Alt/ menu to efficiently look up functions by name (For me, its faster than using a cursor to work thru the nest of menus). If you design your function names so they differ from the built-in function names, the lookup may take only a few keystrokes)
I've made a simple script in Google Apps Script. The script builds forms based on a spreadsheet, the script itself is part of the spreadsheet. It adds a menu item. People would like to use it. They are non-technical people, so I would like to make the installation of my script as easy as possible. With 'installation' I mean a way to 'import' my script into their spreadsheet and automatically set up the needed triggers so the menu item becomes visible. It should be possible for anyone to install it.
I've been thinking of the following solutions:
Publishing as an add-on: my script wouldn't qualify, and even then I can't wait for Google's approval.
Copy-paste. I don't like this, it's way too complicated.
I've looked at this question: https://stackoverflow.com/questions/5334751/how-do-i-share-a-script-i-wrote-with-my-co-workers-on-the-same-google-apps-accou, but the people wanting to install it are not on the same domain in my case. The question is also 3 years old.
EDIT: As it turns out, there doesn't seem to be a solution. I've filed a feature request here: https://code.google.com/p/google-apps-script-issues/issues/detail?id=4122&thanks=4122&ts=1403949074
If your Google Account administrator allows you, you can share scripts/spreadsheets outside your organisation either by sharing directly with another person with a Google Account (Gmail or Google Apps) or by making it public (share with a link or published online).
https://support.google.com/drive/answer/2494822?hl=en
Keep in mind that if you use the Script Properties to store values, each time someone uses the shared script it will overwrite the values. In a shared context it is best to use User Properties instead. This way each user can store their own values.
https://developers.google.com/apps-script/guides/properties
There is no way to import a script in an existing spreadsheet , the "normal" workflow is , in a way, the reverse process, that's to say create a sheet from an existing template that already has the script in it and start to work with that copy.
From your description I'm not sure this method could be useable but I'm afraid there is no other way if you want people who will be using it should not go into the script editor at all.
There would be a couple of functions to write that should run at install time and would create the triggers (if needed) and trigger the authorization process.
I made such a SS some time ago that needed authorizations and I added an "install" menu that made its use quite simple (example here on a friendly hosting site).
I know this is probably not the answer you were expecting but it was definitely too long to fit in a comment anyway.