Google Apps Script Tutorial to Fill out Google Docs Template With Dynamic Data Using Google Forms
Dec 21, 2025
Buy the full source code of application here:
https://procodestore.com/index.php/product/google-apps-script-tutorial-to-fill-out-google-docs-template-with-dynamic-data-using-google-forms/
Show More Show Less View Video Transcript
0:00
Uh hello friends, today in this tutorial
0:02
I will be showing you that how basically
0:04
you can fill out the Google forms inside
0:06
your Google app script and insert this
0:09
information inside your Google docs and
0:12
create dynamic files here. So you can
0:14
see that this is a simple form here
0:16
Google form and basically it contains
0:18
three questions out there. What is your
0:19
name, age and which country you belong
0:22
to. So you can see that guys we are
0:24
saving all this information inside a
0:26
table like structure. This is
0:28
spreadsheet. Here we are storing this
0:30
information. You can see here this is
0:32
containing these information. Let me
0:34
just fill out these entries. So we have
0:35
these three columns out there for the
0:37
name, age and country. We have also
0:39
storing the time stamp as well. And
0:41
after that guys, it will automatically
0:43
create these files inside our Google
0:44
drive and it will store this information
0:46
inside this. We have also got a template
0:49
which basically stores this name, age
0:51
and country. These are basically the
0:53
template variables we are storing inside
0:55
these double curly brackets. So this
0:57
name will be inserted dynamically. Name,
0:59
age, country. Now let me ins just insert
1:02
this. We fill out the name here. John
1:05
Williamson. And if I write age, let me
1:08
put here. And the country as well.
1:12
[snorts] So you can just uh the form is
1:14
available. You can see this is the
1:15
unique link which is live on the
1:16
internet. You can just share this form
1:18
with any persons around the world. You
1:20
can just take the information from the
1:22
customer information form. Here the form
1:24
is submitted. You will see your response
1:26
has been recorded. And if I show you
1:28
inside your spreadsheet, automatically
1:30
this data is inserted. You will see the
1:32
timestamp. This is the name and this is
1:34
the age and this is the country. So
1:37
whichever information that we submitted
1:38
right here guys, it is now it is
1:40
received inside the Google spreadsheet.
1:42
And now let me show you the Google drive
1:44
also. You will see this exactly this
1:46
file is created and you can see the data
1:48
is constructed inside Google Docs. You
1:50
can print it out. You can convert this
1:52
to a PDF document as well. So in this
1:55
way you can take the user input data.
1:57
You just need to share this form with
1:59
your users. They will fill out the form.
2:01
Let's suppose I insert another entry
2:04
here. Click on submit. And now you can
2:06
see another record is inserted. And if I
2:08
check the automatically you will see
2:10
this response has been recorded here.
2:12
Name, age, country. And once again a new
2:14
entry will be added inside your Google
2:17
Drive. And automatically you will see
2:19
that if I refresh it, basically a new
2:22
entry will be there. You can see
2:25
this is a new entry here. So in this
2:27
case guys, you can dynamically generate
2:30
Google Docs with dynamic data coming
2:32
from these Google forms and you can
2:34
insert them into spreadsheet. First of
2:36
all, this data is sent to the
2:38
spreadsheet where we are storing all
2:40
this data inside this table and then we
2:42
are inserting this data which is stored
2:45
inside spreadsheet to this Google docs.
2:48
So all we are doing it we are running a
2:50
simple Google app script guys. Google
2:52
appcript if you don't know it's
2:54
basically a platform which is provided
2:57
by Google which
2:59
is used to interact with different
3:01
Google services such as YouTube drive
3:03
API Google doc spreadsheet all that
3:05
stuff so it's a scripting platform
3:07
developed by Google and first of all now
3:10
to get started here you I have given all
3:12
the source code in the description of
3:14
this video here so if you want to get
3:15
all the step-by-step instructions you
3:17
can go to the description of this video
3:19
and follow this step and now guys in
3:21
order to create this. First of all, you
3:22
need to go to your Google Drive and
3:24
basically we will be constructing a
3:26
Google form which will be able to take
3:28
the input of the user. So click on this
3:30
new option here guys. So this is the new
3:32
option and click on the Google form and
3:35
first of all guys you need to create a
3:37
folder where all this information will
3:39
be stored. So simply just create a
3:41
folder which is uh info and click on
3:44
this create button. So this will create
3:45
a folder inside your Google drive. So
3:47
this is the ID of the folder that we
3:50
want. Simply copy this ID. We will need
3:52
this later on. And here inside this
3:54
folder guys, we need to create a simple
3:56
Google form. So simply go to the menu
3:58
and just select here Google form. And
4:00
basically you can rename this form to
4:02
anywhere. Let's suppose I say here
4:04
customer
4:08
registration form.
4:13
So this is the name of the form. You can
4:15
also provide a description as well. And
4:17
after this guys basically you can uh add
4:19
questions here. So I will add a question
4:21
here.
4:24
What is your name? So I asked this. So
4:27
you can also provide multiple choice
4:29
questions chat box also. You can upload
4:32
images as well. But I will be selecting
4:34
here short answer. And here the user
4:37
will answer the question. You can add
4:39
one more question here. Let's suppose
4:41
what is your age?
4:44
This will also be a short answer and
4:47
third answer will be which country
4:51
you belong to. So this is the third
4:53
question. This will also be a short
4:55
answer. So these three questions are
4:57
there guys. Now you need to go to
4:59
responses and whenever the user submit
5:02
the response you need to store all this
5:04
information in the spreadsheet. You will
5:06
rename this spreadsheet to let's suppose
5:09
customer. And now click on this create
5:12
button. So this will create this
5:13
spreadsheet guys and it will open it
5:15
inside a new window. And you can now see
5:17
this automatically will contain these
5:19
four fields out there. Timestamp, name,
5:22
age and the country. Timestamps will
5:25
automatically be inserted which is the
5:27
date and the time. Now you need to go to
5:30
the extensions here guys and select here
5:32
appcript. And here we will be writing
5:34
our appcript code here and also guys we
5:37
also need to design the template for the
5:39
Google document Google docs. Just write
5:41
this and here you just need to go to
5:44
Google Docs here and here click on this
5:47
blank one and inside this we will insert
5:50
a simple table guys. We will be storing
5:52
it.
5:54
So insert a table and it will be 2x3.
6:01
Yeah, it will be I think this will be
6:07
2x3 table
6:09
or I think what we need to do it is not
6:12
2x3 because we are storing three
6:14
columns. So we need three columns here.
6:17
Three columns
6:20
and three rows. I think this will be
6:23
enough. Name, age, country. No, let me
6:28
select it once again. I think name, age,
6:30
country
6:32
2, 3. Yes. 2, 3. This one I need
6:37
name, age, country. Yeah. So this will
6:40
be name. Here you will place the name
6:43
here. This will be age and this will be
6:46
country.
6:48
And uh now to insert the dynamic one,
6:50
you will put here double curly brackets.
6:52
So this will be name.
6:54
So you can design complex forms here
6:56
guys. So I'm just taking a very simple
6:58
example here. This can be any very
7:00
complex form. If you are building any
7:03
sort of invoice, if you are working in a
7:06
company, you want to design the salary
7:07
slip, you can design complex forms. You
7:10
can also change the background color as
7:12
well. All sort of designing you can
7:14
done. So you just need to basically copy
7:17
this ID guys that we will need this ID.
7:19
After this you just need to go to this
7:21
Google app script here and basically we
7:23
will now write the code which is
7:25
required for this. So first of all guys
7:28
we will make a simple function
7:32
which is fill form. This will be the
7:34
function and inside this guys first of
7:37
all we will take all these uh three
7:39
values. First is a time stamp and this
7:42
will be passed event object. Basically
7:45
whenever you submit this form this event
7:47
object will be automatically passed
7:49
here. So right here first of all we will
7:52
get the values like this E dot values
7:54
zero and now we will be getting the name
7:58
by E dot values 1
8:01
and then we will be getting the age
8:03
similarly E dot values and two and then
8:07
we will be getting the country which is
8:08
E dot values three. So this will get the
8:12
name name age country guys. So
8:14
automatically from the form and now we
8:17
just need to get the actual file of the
8:20
Google Docs. So we can use this method
8:24
get file by ID and here you need to copy
8:27
paste the ID guys which is of this one.
8:29
Simply copy this and paste it here. And
8:33
now guys you will be getting to the
8:34
folder. So Google Drive folder drive
8:37
app. So this time you will use get
8:39
folder by ID. So whenever you created
8:42
your folder in Google drive, you need to
8:44
simply copy this ID.
8:47
So simply copy this ID guys and simply
8:50
paste it here. So now you will get the
8:53
folder as well folder reference as well.
8:56
So now what we need to do guys just
8:57
create some space here so that you can
8:59
write your code.
9:02
[snorts] So after this guys we just need
9:04
to basically make a copy of the file of
9:08
the Google Docs file. So we will have
9:10
this method make copy and basically we
9:12
will name the file as age plus
9:16
so whatever is the age of the person put
9:18
a comma and then the name. So this will
9:20
be the name of the file and we will be
9:23
storing it inside our folder. This is a
9:26
folder that we created. So this file
9:29
will be stored inside this folder. After
9:31
this guys we will get the data which is
9:34
there inside this file. We will simply
9:37
call document app and this contains open
9:40
by id. So this will actually open the
9:42
google docs document and we will get
9:47
copy dot get id get id.
9:51
So basically it gets the id of the file
9:53
and it will copy sorry open this file.
9:56
After opening it guys we will get the
9:58
data
10:00
by we will get and we'll store it inside
10:02
body. So in order to get the data we
10:04
will call this method get body. So this
10:07
will actually return all the information
10:09
which is stored inside your Google docs
10:10
which is the name age country. Now we
10:13
dynamically needs to replace these name
10:15
age country which is inside double curly
10:18
brackets. So this is some placeholder
10:20
variables. So now to do this after we
10:23
get this we can use the replace text
10:25
method which is there replace text and
10:28
inside this inside double single quotes
10:31
we will replace this double curly
10:33
brackets
10:35
which is the name with the actual name
10:37
coming from the form Google form. So
10:39
again we will replace text this time for
10:42
the age
10:44
and age will be passed here and again we
10:47
will use the for the country. So double
10:51
quotes.
10:53
So make sure guys this placeholder
10:55
variables need to be same here. Spelling
10:58
need to be same and all that. So please
11:00
check here. So inside country we need to
11:03
insert the country. That's it. After
11:05
this guys we need to save and close this
11:07
file. And this contains a method inside
11:10
doc save and close. So simp it will
11:13
simply save and close the file. That's
11:15
all. So after this guys
11:19
this is all the code required for this
11:22
awesome application. So it is
11:23
communicating with all these three
11:26
services spreadsheet Google docs and
11:29
Google forms. And now you can save this
11:31
function here. Save this project. And
11:33
now inside this inside menu go to
11:36
triggers option. And here we need to add
11:37
a trigger. Triggers is something guys
11:40
whenever you do something inside Google
11:42
appcript basically you can add a trigger
11:45
here and we need to execute this
11:47
function. So simply select this this
11:50
will be a head here and right here from
11:53
the spreadsheet we will be taking the
11:55
event and whenever the form submits so
11:58
we need to select the ons form submit
12:01
and uh notify immediately like this. So
12:04
now click on save and it will ask for
12:06
the permission. So once you do this you
12:09
will be asked for the permission. So it
12:11
is loading the data. So it will take
12:12
some time here.
12:15
So it is saying script authorization
12:16
failed please. Okay. First of all guys
12:19
as you all know we need to first of all
12:22
run this.
12:26
[snorts] So just go to your editor and
12:27
first of all run this application. You
12:29
need to grant the permissions. So you
12:31
need to this will first of all ask here.
12:34
So you need to grant all the
12:35
permissions. So simply do like this.
12:39
Click on allow and once you have all the
12:42
permissions you will be able to run your
12:44
code. So now we can add a trigger simply
12:48
by clicking add trigger and on form
12:51
submit notify immediately. And now click
12:55
on save. Again you need to grant the
12:57
permission guys. It will ask for it. So
12:59
simply go to this process
13:05
allow
13:07
and now this will add a trigger.
13:08
Whenever you submit your Google form
13:10
this information will be saved inside
13:12
your spreadsheet. You can see that and
13:15
now we can simply
13:17
open this form here guys that we
13:20
constructed. Basically let me copy this
13:24
URL. If you see here, this is the URL of
13:27
the form here and make sure that you are
13:29
logging from a different account and uh
13:32
you can even say here incognito window.
13:34
Let me open incognito. I'll let me paste
13:36
it this link here of the form. So this
13:39
form will open right here guys. You will
13:40
see that and uh this is a customer
13:42
registration form here. You can see that
13:44
you need to fill out the information.
13:46
Let's suppose I fill out
13:49
put here age and uh
13:52
click on submit. And now you can see
13:55
your response has been recorded. And
13:57
basically if I now check here one
13:59
response has been received. You can see
14:01
it name, age, country. You can see that.
14:05
And uh if I now check the Google sheet,
14:08
you will see that the time stamp is
14:10
automatically inserted. This is the
14:12
name, age, country. If I check my Google
14:15
Drive, you will see one file will be
14:18
added. One customer is added here. You
14:20
will see
14:22
if I now refresh it here.
14:26
You can see that 25 comma if I see here
14:30
automatically the those values will be
14:32
replaced here. You can see name is
14:34
replaced age is replaced and countries
14:36
also. So this was the template and
14:38
inside these curly double curly brackets
14:40
the name, age, country has been
14:42
replaced. So in this case guys you can
14:44
design complex registration forms. You
14:46
can also uh just design invoice messages
14:49
that will be sent to your email
14:51
addresses. So this will save a lot of
14:53
time because you can get the all these
14:55
values user generated values. You can
14:58
also generate another response here like
15:00
this.
15:01
So you can just create unlimited values
15:04
guys. So it is all automatic process
15:06
here which you can see that it is taking
15:09
the values and it is generating these.
15:11
You can see
15:14
and also inside spreadsheet also this
15:16
data is inserted. So this is a really
15:18
good application guys. Hopefully you
15:19
will get to understand how to implement
15:21
this. All the source code is given in
15:23
the description of this video. Thank you
15:25
very much for watching this video and I
15:27
will be seeing you in the next
