Script permission to run script in a doc auto created by form submission

35 views
Skip to first unread message

Clark Air

unread,
Jun 29, 2022, 8:02:09 PM6/29/22
to Google Apps Script Community
I am trying to create a doc that is auto created from a form submission. I have figured out how to insert text in all of the areas of the doc using a script in the sheet created from the forms answers. I am having trouble inserting a link based on the answer of two of the questions in the form. One of the questions has 3 possible answers and another has 7. So there is 1 of 21 different links that I need to input into the doc based on the form. When the form is submitted I found a way to replace a string in the doc with the needed link. I did this by writing a second script in the google doc template that is being populated from the answers in the form. However whenever a new doc is created from a form submission I must manually give the script permission to run in the new doc. Is there a way to automatically grant permission to run the script and make the script run. Or is there another easier way to input one of the links using the original script in the sheet.
I appricate any suggestions.

Phillip Bainbridge

unread,
Jun 30, 2022, 6:16:43 AM6/30/22
to Google Apps Script Community

Hi Clark

How are you doing the Doc creation from the Google Form bit? Here's how I do it: https://www.pbainbridge.co.uk/2020/05/create-google-doc-from-form-submission.html

Regarding the insertion of a link in the Doc, are you using something like 'setText' and 'setLinkUrl'? https://www.pbainbridge.co.uk/2021/11/replace-text-in-google-doc-with.html

Kind regards
Phil

Ron Meske

unread,
Jul 1, 2022, 10:24:30 AM7/1/22
to Google Apps Script Community
Hi Clark,

What I have found, based on the link Phil supplied and an answer to an issue I had with the onFormSubmit, is that you will need to set it up this way:
1. Form - Link it to a Google Sheet
2. Sheet - Attach your script to this sheet and setup an Installable Trigger to call your function with the trigger onFormSubmit.  This script will receive the response as part of the event and with that you can create your document and insert data from the response.
3. Doc - Do not attach a script.

Hope that helps.

Ron
Reply all
Reply to author
Forward
0 new messages