Use Google Workspace to create Google Docs
Use Google Workspace to automate Google Docs in SAP Build Process Automation
Overview
You will learn
- 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
Prerequisites
- Complete Google Authorization tutorial
- Install and set up the Desktop Agent 3 to run the automation
Steps
Intro
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.
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.

Create Automation In the Create Automation window, enter Google Workspace-Docs as name and An automation to use Google Docs as a description.

Create Automation You will be navigated to the automation editor of the newly created automation.
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.

Google Authorization Automation 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.

Create Document 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.

Insert Text 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
textToInsertparameter, 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.
Insert Text 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.

Create Header For
headerText, enter the following header to insert: SAP Build Process Automation and select the expression in quotes.
Create Header 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.

Create Footer For the parameter
footerText, enter the following footer to insert: SAP and select the expression in quotes.
Create Footer Choose Save.
Choose Test.
Fill in the Environment Variables:
- For
userEmail: your Gmail user email - For
serviceAccountKeyPath: the full path to the json file

Replace Text - For
Choose Test.

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.

Test After opening it, you will see that the header, footer and text were successfully inserted in the document as well.

Test
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).
You can find the Document Id of the Google Document in the URL.

DocID Select the activity. Under Input Parameters, for
documentId, enter the id of the document you want to retrieve from Google Drive and select the expression in quotes.Choose Save.

Get Document
Search for the activity Get Document (Google Docs) activity. Drag and drop the activity to your workflow. Under Input Parameters, for
documentId, choose the pencil to open the expression editor.Choose as Variables:
createdDocument>documentId.Choose Save expression.
Save your work.

Get Document
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.

Replace Text Now you will enter the parameters as below.
Parameter Name Value textToBeReplaceduse replaceTextcreate and update matchCasetrue CAUTION: Always remember to select the expression in quotes.
matchCaseparameter indicates whether the search of the text is case-sensitive.
Replace Text 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.

Replace Text
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

Replace Text - For
Choose Test.

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.

Test After opening it, you will see that the text “use” was replaced by the text “create and update”.

Test
Resources
Discussion
Share feedback on this tutorial or join the conversation in SAP Community.