Use Google Workspace to create Google Docs
- How to use Google Workspace to automate the creation of a new Google document
- How to insert header, footer and text in Google Document
- How to retrieve a specific document and replace text in it
Prerequisites
- Complete Google Authorization tutorial
- Install and set up the Desktop Agent 3 to run the automation
In this tutorial, you will build an automation that will create a Google Document where you will insert a header and a footer as well as some text. You will then retrieve the Google document and replace some text in the document.
- Step 1
In the Lobby, select the Google Suite project that has been done as part of previous tutorials as mentioned in pre-requisites.
In Build Process Automation, choose Create and then select Automation.
In the Create Automation window, enter Google Workspace-Docs as name and An automation to use Google Docs as a description.
You will be navigated to the automation editor of the newly created automation.
- Step 2
-
In the Automation Details panel, under Automations, drag and drop the Google Authorization automation you created as mentioned in the pre-requisites.
This automation will allow to authorize your Google Workspace account.
-
You will automate the creation of a new Google Document in your Google Drive.
In the Automation Details panel, under Tools, search for the Create Document (Google Docs) and drag and drop it into the workflow.
This activity takes an optional parameter for title of document. If not specified untitled document will be created.
-
Select the activity Create Document (Google Docs). Under Input Parameters as a title type Automation Document and select the expression in quotes.
Now you will add content in the document. You will use Insert Text (Google Docs) activity to do so.
CAUTION: Currently there is no support for styles in Google docs automation activities and this has to be done manually.
-
In the Automation Details panel, under Tools, search for the Insert Text (Google Docs) and drag and drop it into the workflow. Then perform the following steps:
-
Select the activity. Under Input Parameters, for
documentId
, choose the pencil to open the expression editor. -
Choose as Variables:
createdDocument
>documentId
. -
Choose Save Expression.
What is going on?
Google Documents can be updated with other activities using the document Id. By entering the Id of the document you would indicate the automation in which document it has to insert text in.
-
-
For
textToInsert
parameter, enter the following text: Hello from SAP Build Process Automation. Today you will learn how to use Google docs. Please select the expression in quotes and hit enter. -
In the Automation Details panel, under Tools, search for the Create Header (Google Docs) and drag and drop it into the workflow. Then perform the following steps:
-
Select the activity. Under Input Parameters, for
documentId
, choose the pencil to open the expression editor. -
Choose as Variables:
createdDocument
>documentId
. -
Choose Save Expression.
-
-
For
headerText
, enter the following header to insert: SAP Build Process Automation and select the expression in quotes. -
In the Automation Details panel, under Tools, search for the Create Footer (Google Docs) and drag and drop it into the workflow. Then perform the following steps:
-
Select the activity. Under Input Parameters, for
documentId
, choose the pencil to open the expression editor. -
Choose as Variables:
createdDocument
>documentId
. -
Choose Save Expression.
-
-
For the parameter
footerText
, enter the following footer to insert: SAP and select the expression in quotes. -
Choose Save.
Which activity is used to retrieve an existing Google Docs document ?
-
- Step 3
Choose Test.
Fill in the Environment Variables:
- For
userEmail
: your Gmail user email - For
serviceAccountKeyPath
: the full path to the json file
- For
Choose Test.
The testing was successful.
You may go to your Google Docs in your Google Drive and you will see that a new document named Automation Document was successfully created.
After opening it, you will see that the header, footer and text were successfully inserted in the document as well.
- Step 4
You will add an activity in the automation to retrieve a Google Docs document from your Google Drive that was created in the above steps:
- In the Automation Details panel, under Tools, search for the Get Document (Google Docs) and drag and drop it into the workflow.
There are two ways to retrieve the document id of the Google Document, either through the URL of Google Document or through the Create Document (Google Docs) activity (step2 of the automation).
- Step 5
Next step is to replace the matching text in the Google Docs document with a new value.
In the Automation Details panel, under Tools, search for the Replace Text (Google Docs) and drag and drop it into the workflow.
Select the activity. Under Input Parameters, for
documentId
, choose the pencil to open the expression editor.You need to specify the Id of the document in which you want to replace some text. You have already retrieved the document from the activity Get Document (Google Docs). Map the parameters accordingly as explained below.
Choose as Variables:
googleDocument
>documentId
.Choose Save Expression.
Now you will enter the parameters as below.
Parameter Name Value textToBeReplaced
use replaceText
create and update matchCase
true CAUTION: Always remember to select the expression in quotes.
matchCase
parameter indicates whether the search of the text is case-sensitive.Lastly, you will disconnect your Google Workspace Account using the activity Disconnect (Google). In the Automation Details panel, under Tools, search for the Disconnect (Google) and drag and drop it into the workflow.
Save the automation.
- Step 6
You will now test your automation.
Choose Test.
Fill in the Environment Variables:
- For
userEmail
: your Gmail user email - For
serviceAccountKeyPath
: the full path to the json file
- For
Choose Test.
The testing was successful.
You may go to your Google Docs and you will see that the document called Automation Document was successfully updated.
After opening it, you will see that the text “use” was replaced by the text “create and update”.