Aim of the puzzle: Use Apps Script to complete the final step in writing a function to automate contract creation.
Walk through of the solution: For the last topic of this course, you’ll use Apps Script to create a function that automates the process of creating contracts.
In this puzzle, you’ll complete the last step of the main function.
The main function has been divided into 3 steps:
- Open a spreadsheet and get a range of values
- Loop through every row in the range and call
makeCopy()
to create and name a new copy of the contract - Open each copy and use
updateDoc()
to replace its placeholder text with text from the spreadsheet
To complete the puzzle, complete step 3.
Inside the for…of loop that’s inside the main()
function declaration, create a variable called copy
that stores the document accessed by DocumentApp.openById(copyId)
. Then, right below copy
, create a variable called edits
that stores the nested array:
[
[ 'CLIENT', row[0] ],
[ 'FEE', row[1] ],
[ 'SERVICE', row[2] ]
]
Finally, below edits
, call the updateDoc()
function. Set the 1st argument to copy
and the 2nd argument to edits
.
JavaScript concepts: Variables, Strings, Nested Arrays, Array Indexing, Arguments, Function Declarations, Function Calls
Apps Script concepts: DocumentApp
, .openById()