Gaining permission to run a macro [duplicate] - google-apps-script

This question already has answers here:
"Sign in with Google temporarily disabled for this app" error when trying to authorize a script
(5 answers)
Closed 2 years ago.
I'm on a windows 10 computer using a Chrome browser.
My problem is getting permission to run a Macro. For an individual user there are two pop ups that can appear when you record a macro and try to run it. One pop up has an 'Advance' link which warns you of the danger, but then lets you proceed with the 'unsafe' macro.
Sometimes, however, you get a pop up saying the approval process has been temporarily suspended and there is no 'Advanced' link to allow you to proceed. In essence, you cannot record and run a Macro.
I've been messing with this for days trying to figure out what causes one popup to appear as opposed to the other. I am completely mystified.
Last night someone shared a sheet with me. I made a copy, renamed it and moved the copy into my root drive which I share with no one. I recorded a simple macro, was told I needed permission, got the popup with the advanced link and was able to run the Macro.
This morning the person shared another sheet with me and I repeated the exact same steps of copying, renaming, moving the copy o my non-shared root folder and tried to record a Macro. No luck. I got the popup saying permissions were temporarily suspended with no advance link to let me move ahead and run the macro. How can this act so differently 12 hours later?
Can anyone offer me an explanation of what is happening? I'm now two days behind on delivering a promised project trying to figure this out. Thanks for any help anyone can provide.

Instead of using a Google Sheets Macro use a G Suite editor add-on.
The cause of the "Advanced link" is not being shown is because there are "too many" users running the unverified script
From https://developers.google.com/apps-script/guides/client-verification
User cap
The number of users who can authorize an app via the unverified app flow is capped to limit possible abuse. See OAuth application user limits for details.
NOTE: You might not have to publish an add-on as nowadays the verification process can be done without adding the G Suite Marketplace SDK, but if you will need to use the same code on multiple spreadsheets you will only need to do the verification once whil having multiple copies of a spreadsheet with bounded code will require to do the verification for each copy.

Related

Turn OFF “Authorization is required” for Google Sheets Script for own team

We are a small company which just switched from paper to tablets (Surface GO Win10 Home) and we have one particular sheet which is used for every order (about 100 orders per month). This Google Sheet acts as a template for every single order and includes some easy code which is written in a bound Apps Script project, to handle things like switching the status from started to finished, copying some cells etc.
My problem is, when someone of the team wants to use the created "buttons" in the sheet to activate the script, it asks for authorization for the script the change the sheet. If you enable it, everything works fine but then for every new order you have to enable it again, and again, and it gets really annoying for every team member.
I tried somehow to
turn it off in the security options as administrator
tried it in the GOOGLE CLOUD PLATFORM under API's and services
tried to make the code somehow public in the script editor options
...but nothing seems not to work. I used VBA programs a lot in Excel VBA but it was more a hobby and I'm not a computer scientist, otherwise it would maybe be easier to solve this problem.
Is there an easy way so every one of my team can work with the sheets created out of a template without any request from Google for authorization every time.
Kind regards.
The reason for the popups is that Google Apps Script is not part of Google Sheets itself, it's a separate application that uses OAuth 2.0 to get the permissions to make the requests by calling the APIs. The popup shows the scopes you are authorizing for. This means that you can't disable that.
Note that apps script could do more things that just edit the spreadsheet itself; it could get other files, get your personal information, call external servers, etc. Also, the authentication process will only happen once per file.

Google Sheets script requires authorization, oauth client says it was deleted, but it's all inside our domain

In 2014, a user in our company created a series of spreadsheets to track money, and he's now retired. Everything worked until recently. (Also, we are gsuite customers, which is relevant since the sheets are shared within the company.)
I am trying to run a script attached to the "Summary" spreadsheet to move everything to the "History" spreadsheet, and then reset the "Summary" to this month. This code has worked since 2014, including when the regular user switched from July 2020 to August 2020. Now, when I run the script from the sheet, it says "Authorization required: A script attached to this document needs your permission to run." Based on this google documentation, there's nothing I can do to make it not ask permission.
Once I hit continue, it says "Authorization Error. Error 401: deleted_client The OAuth Client was deleted."
This spreadsheet hasn't been shared outside our domain, and shouldn't be used outside our domain. Google says here that "Verification is not required for Apps Script projects whose owner and users belong to the same G Suite domain or customer." which is exactly what we have.
So why does it require authorization?
As far as I know, nothing has been deleted. The retired user's account is still open.
I have also tried going into console.developers.google.com and created a project with oauth credentials, but that doesn't seem like what is needed.
I can update with code if you feel it's necessary, but it doesn't seem like a code problem.
Edit: Working on a minimal reproducible example, but it's taking a while. I tried to just have the Summary and History spreadsheets, but part of annonymizing the data involved removing links from the 6 department spreadsheets. Removing those "fixed" the problem. Instead of saying "The OAuth Client was deleted." it acted as normal. (It showed my logged in account, I clicked it, etc, it worked.)
The issue seems to be related to importing data from 6 spreadsheets into one, and then moving all that data. I'm working on that.
Using what Alan Wells said about the "Cloud Platform Project," I found this StackOverflow post and followed it. I made a copy of the script and deleted the old one. I refreshed the spreadsheet, and now the authentication works!

How do I unlock "padlocked" Apps script files in Google Apps Script?

I have a script project in which some "padlocked" .gs files are shown. I can't edit or delete them.
I need to use those files, but the person who locked them is unavailable.
I was trying to unlock the files using methods from the class LockService but it doesn't seem to work that way.
How do I "unlock" these files so I can edit them?
I figuered it. The padlock doesn't point to actual files withing this script. There is a library in a standalone script containing these files. When I use debugger it reaches these files from a standalone library and they are shown within the script with a padlock. So padlock simply means that those modules are from a separate script file! So it's not a lock.
I handled it by creating same modules withing the script and simply renamed few functions. So I am able to use debug for all my route.
Unfortunately, only the owner of the file or an admin of your domain (if you're using G Suite) can do that.
I had the padlock appear on two projects I own, and am the only editor of, without understanding why they first appeared. They appeared on my work laptop but not my home laptop. At work I'd been signed into one browser window with both my work and personal accounts. When opening the google sheet that contains the script it opens signed in as my work account. However, when opening the script from the sheet, the script opened but signed in as my personal account (that also has access). I guess this shouldn't really happen but it did. The solution was simple though, I just had to use the drop down to select my work account, which opened a new window for the script without a padlock and I was able to edit as normal. Was quite confused for a while... phew!
I had the same problem. As it turned out none of the above fixed it although similar but different to the other person who fixed his. In my case i have multiple chrome users on a single machine. I log in at the browser level.  I was in the browser for user A who also owned the file. When I opened up the bound google script project attached to the gooogle sheets file, it opened up as it should but locks were on each tab. I was confused for about 10 minutes.
In the upper right corner of the interface, there was a drop down that was showing User B email address even though above that, at the browser level I was clearly in the browser of user A. I clicked that drop down and changed to User A and the locks disappeared.  It seems they have an odd way of managing users on these gsp's that subverts the browser level user login. 

Is there a way to run scripts when someone is answering to a Google Form?

So, here at the company I work for we usually manage the workforce weekends schedules in a very manual way using Excel, and then upload a pdf version of the sheet in our intranet so everyone can see their own schedule for the rest of the month and look up for swaps if they need to.
The problem is that the workforce recently has grown up a lot and we're spending a lot of time validating and reuploading the schedule everytime we need to do the shift swaps. So I decided to start a project using Google Sheets and Google Forms, so we could just show iFrame of the sheet in the view mode, and their supervisors could make their swaps via a google form, which would update the sheet and they could see it happening on-the-fly, I guess.
Now that I gave you some context, what I really need is to discover if there's actually a way to accomplish what I'm trying to, because I already stuck once realizing that the script running from a Google Sheet only works with edit permissions (I need to no one have permission to change manually the sheet and preferably not even needing to link account to Google), but now I realized even when scripting inside of the form it doesn't run when people are answering to the form, but only in the edit mode, which I think it's useless for me since questions should be dynamic (the form would look for the available weekends and employees in the sheet using some validations).
For example, the code below runs when I open the form in Edit mode, but not when I open the shared link:
function onOpen() {
var ui = FormApp.getUi();
ui.alert('test');
}
So, my question is if this project is possible using Google Scripts and the suite, if there's some kind of option or permission I'm missing to make it work, or if it's worth I try to do it using an not inbound countainer script, or maybe HTML Service, or if I should forget Google and look for another tools for this job.
Thanks.

I am getting below email on daily basis. How to stop it?? Summary of failures for Google Apps Script: Eml Manager [duplicate]

This question already has answers here:
Summary of failures for Google Apps Script: Not found
(2 answers)
Closed 5 years ago.
I am getting below email on daily basis. How to stop it??
Summary of failures for Google Apps Script: Eml Manager
If you are not supposed to be running any scripts then you can just open the script editor, click on Resources → All Your triggers and then remove triggers you do not want. You can also simply disable notifications by clicking on the Notifications link to the right of the trigger and removing your e-mail.
Otherwise, in a similar manner, go to the Eml Manager and fix the code :)
If you are getting 'Summary of failures for Google Apps Script' on daily basis, you should look forward to fixing your code because code isn't behaving as you had expected.
Here are few of the reasons which can cause those failure emails:
Too many simultaneous invocations on the google app to which you have attached your appscript
Authorization or Authentication issue (a new user of the script has to authorize it first time)
Script took more than 6 minutes to complete (6 min is the limit)
If you have created programatical triggers, and forget to delete them once it has served the purpose, it will keep on creating new triggers and there is total trigger limit per script is 20.
In some cases, server can also be too busy to trigger your script but that rarely happens.
Also, if your script is taking too longer to complete, you should look forward to reducing the looping and also reducing writing operations on google apps(as it keeps on saving every change you made). Also, use in built formulas etc as much as possible.
If your code is totally fine according to you, then you can stop those failure emails by removing your name from the notifications option of your triggers as #Vytautas mentioned.