I've created a WebApp which takes a spreadsheet id, a trello's list id, trello api key and a user's trello token as input.
Upon getting the input, the Google app script creates an installable trigger on the spreadsheet such that the trigger will get executed whenever someone submits the google form linked with the spreadsheet and creates a trello card in the specified trello list.
Initially I tested this script by creating a google form (and hence a google sheet) and by giving the script the required input mentioned above. This worked completely fine, the script was successfully able to create a trigger on the specified spreadsheet.
The problem was that the google form and the google app script project were both linked to my Google account and hence there was no trouble for me to access my own resources programmatically. As soon as I tried to create a trigger on a sheet that was of some other user I was not allowed to do so.
I had published this script as webapp with execute app permission as Me and anonymous access to the app.
I used Postman to make the api calls to the script and when submitting the input required to create the trigger I'm getting an HTML that says this:
I also tried to change the execution permissions to this:
But then got this response:
I'm assuming that I'll need to get permission from the user to be able to set a trigger on his/her resource but I'm not sure how to achieve that any suggestions would be appreciated.
Just for the sake of completeness, here is the code to set up a trigger on a spreadsheet.
function getTrigger(data){
return ScriptApp.newTrigger("createTrelloCard").forSpreadsheet(data["spreadsheet_key"])
.onFormSubmit()
.create();
}
Related
My Google Sheets script programmatically creates a form, and then attempts to change the name of the Form Responses tab that was added to the spreadsheet. The form is created fine, but I can't seem to access the responses tab, at least from the same function. It appears that the Sheets object is not getting updated with the new tab.
However, if I run a separate function later that tries to access the responses tab, this works fine.
Any suggestions for how to get the Spreadsheet to update and reflect the new set of Sheets? I was hoping I could use something like a setTimeout but doesn't sound like that is available in Google script. A time-based trigger wouldn't work because I want this function to be able to happen quickly (not after a minute).
I made some script with my spreadsheet, which uses some Trigger and SendEmail functionalities. I have menu items in spreadsheet to control these triggers and sendemails.
Now when I share this spreadsheet with someone other, when he tried to access the trigger or sendemail functions from menu, the script asks for authorization as that user. IF authorized it will function as that user. e.g. send email as that user or make a new trigger as that user. This makes things double and useless
I want that any user accessing the script can use those functionalities, but won't require authorization to run as that user. The script should run as the creator of the sheet, so that no double triggering occurs. How should I do it?
You could create a web-app. Web-apps have the ability to run either as the user himself, or as the developer/publisher.
Under Execute the app as, select whose authorization the app should
run with: your account (the developer's) or the account of the user
who visits the app (see permissions).
https://developers.google.com/apps-script/guides/web
This web-app wouldn't have a sheet linked to it, but if you only use 1 sheet you can have the web-app access the sheet through the ID of the sheet. You could use your existing menu-items to trigger the webapp
Would this be a possible solution for your problem?
I have a spreadsheet that functions as a template for weekly reports. At this point I copy the undated template sheet using DriveApp to a file that has a date in its name. The user is shown the date-specific spreadsheet and can interact with it. When done the user instigates a function that copies of portion of the spreadsheet data to a third file.
Every time the user calls the function an authorization request is shown. I am trying to avoid that authorization request. Is this possible?
I am using a stand-alone Google Apps Script to copy the original template to the date-specific file. I have considered trying to perform all of the UI there. However there are too many contingencies to make that practical. As it stands now once the template is copied then the stand-alone script returns the URL of the date-specific file and ends.
Every time the user calls the function an authorization request is shown. I am trying to avoid that authorization request. Is this possible?
Publishing your script as an add-on would facilitate this; each user would need to authorize the add-on once, and that authorization would remain in effect in any sheet the add-on was used in.
I want to process values submitted from a Google Form when they get saved in the associated spreadsheet. I have an app script associated with the form (as it adds an addon menu there and is suppose to be used from FormApp), and this one install the trigger on destination spreadsheet as following.
ScriptApp.newTrigger('onFormSubmit').
forSpreadsheet(destId).onFormSubmit().create();
function onFormSubmit(e) { Logger.log("--> submit"); }
I also have added an email notification (Immediate) on the trigger.
The trigger appears in project triggers. Calling the onFormSubmit function from editor, or on other event, is working and debug statement is written in the log.
When the form is POSTed, I don't either see anything in the log, nor receive any mail notification.
What's wrong there?
I am trying to send a mail with attaching a file available in my google drive using following google scripts
var file=DriveApp.getFileById('1qZVK0UZ1jLbDdj10FXZqeAVEodvxEy2Bs');
MailApp.sendEmail('xyz#gmail.com','subject','body',{attachments[file.getAs(MimeType.PDF)]});
when I run above script manually it runs fine, email gets sent. But when I run it using form Submission trigger it gives error "You do not have permission to call openById"
steps that will reproduce the problem?
create a google form.
write above scripts on script editor and add a trigger with submission of the form.
fill and submit the form then you will get above error into mail from 'apps-scripts-notifications#google.com'
Please help.
I ran into this same issue, but felt it was a little silly to have to use the FormResponses Sheet to get the submission event (I mean there's a trigger on the Form Apps Scripts for a reason, right?).
All I had to do was to Remove and Re-add the trigger for From form --> On form submit. When I added it, challenged me for OAuth permissions to view and use my google drive.
Immediately after this, I was able to run on a Forms Apps Script Submission trigger again.
I found this when creating the script on the Form itself.
To solve the problem first have you form responses sent to a spreadsheet.
From you form go to Tools > Script editor... copy you script and delete any triggers you have set up there, you won't be needing this script anymore.
Now click on View responses button in your form to open the spreadsheet.
Go to Tools > Script editor... (for the spreadsheet).
You should start with a blank project.
Delete anything in there and paste in your script.
Save and name you project.
Now set up your triggers as normal. You will find the third drop down list of the new trigger has the option On form submit.
Once your script is authorised any time the form is submitted the event will trigger and will have access to the DriveApp.
Once you've tested and got it working I would go back to the form and delete the script project in there. I do that to keep things tidy and save confusion if I come to alter the script later and have forgotten which one is actually live.
I don't know if there is a limitation with Google Forms that limits their access to Drive or something.