You can create and attach Google GSuite Docs to your Documents using your predefined GSuite Templates.
These Templates could use variables from Doctype that will be automatically filled.
Frappe allows you to use Google's Gsuite documents as templates, generate from them a new Gsuite document that will be placed in a chosen folder. Variables can populated in both the body and the name of the Gsuite document using the standard Jinja2 format. Once generated, the Gsuite document will remain associate to the DocType as an attachment.
The Gsuite document is generated by invoking the "attach file" function of any DocType.
A common use cases of this features is populating contracts from customer/employee/supplier data.
## 1. Enable integration with Google Gsuite
@@ -21,52 +24,51 @@ These Templates could use variables from Doctype that will be automatically fill
### 1.2 Get Google access
1. Go to your Google project console and select your project or create a new. [https://console.developers.google.com](https://console.developers.google.com)
1. Go to your Google project console and select your project or create a new one. [https://console.developers.google.com](https://console.developers.google.com)
1. In Library click on **Google Drive API** and **Enable**
- Authorized redirect URI as **http://{{ yoursite }}/?cmd=frappe.integrations.doctype.gsuite_settings.gsuite_settings.gsuite_callback**
- Authorized redirect URI as `http://{{ yoursite }}/?cmd=frappe.integrations.doctype.gsuite_settings.gsuite_settings.gsuite_callback`
1. Copy the Client ID and Client Secret into **Desk > Explore > Integrations > GSuite Settings > Client ID and Client Secret**
1. Save GSuite Settings
### 1.3 Test Script
1. Click on **Allow GSuite Access** and you will be redirected to select the user and give access. If you have any error please verify you are using the correct Authorized redirect URI.
1. Click on **Allow GSuite Access** and you will be redirected to select the user and give access. If you have any error please verify you are using the correct Authorized Redirect URI.
You can find the complete URI Gsuite redirected to in the final part of the URL of the error page. Check that the protocol `http://` or `https://` matches the one your using.
1. Click on **Run Script test**. You should be asked to give permission.
## 2. GSuite Templates
### 2.1 Google Document as Template
1. Create a new Document or use one you already have. Set variables as you need. Variables are defined with ***{{VARIABLE}}*** with ***VARIABLE*** is the field of your Doctype
1. Create a new Document or use one you already have. Set variables as you need. Variables are defined with `{{VARIABLE}}` with ***VARIABLE*** is the field of your Doctype
For Example,
If this document will be used to employee and the Doctype has the field ***name*** then you can use it in Google Docs ad {{name}}
If this document will be used to employee and the Doctype has the field ***name*** then you can use it in Google Docs ad `{{name}}`
1. Get the ID of that Document from url of your document
1. Get the ID of that Document from url of your document.
For example: in this document url `https://docs.google.com/document/d/1Y2_btbwSqPIILLcJstHnSm1u5dgYE0QJspcZBImZQso/edit` the document ID is `1Y2_btbwSqPIILLcJstHnSm1u5dgYE0QJspcZBImZQso`
1. Get the ID of the folder where you want to place the generated documents. (You can step this point if you want to place the generated documents in Google Drive root. )
For example: in this folder url `https://drive.google.com/drive/u/0/folders/0BxmFzZZUHbgyQzVJNzY5eG5jbmc` the folder ID is `0BxmFzZZUHbgyQzVJNzY5eG5jbmc`
### 2.2 Associate the Template to a Doctype
1. Go to **Desk > Explore > Integrations > GSuite Templates > New**
1. Fill the form with:
- Template Name (Example: Employee Contract)
- Related DocType (Example: Employee)
- Template ID is the Document ID you get from your Google Docs (Example: 1Y2_btbwSqPIILLcJstHnSm1u5dgYE0QJspcZBImZQso)
- Document name is the name of the new files. You can use field from DocType (Example: Employee Contract of {name})
- Destination ID is the folder ID of your files created from this Template. (Example: 0BxmFzZZUHbgyQzVJNzY5eG5jbmc)
2. Fill the form with:
- Template Name (Example: `Employee Contract`)
- Related DocType (Example: `Employee`)
- Template ID is the Document ID you get from your Google Docs (Example: `1Y2_btbwSqPIILLcJstHnSm1u5dgYE0QJspcZBImZQso`)
- Document name is the name of the new files. You can use field from DocType (Example: `Employee Contract of {name}`)
- Destination ID is the folder ID of your files created from this Template. (Example: `0BxmFzZZUHbgyQzVJNzY5eG5jbmc`)
## 3. Create Documents
1. Go to a Document you already have a Template (Example: Employee > John Doe)
1. Go to a Document you already have a Template for (Example: Employee > John Doe)
2. Click on **Attach File**
3. O **GSuite Document** section select the Template and click **Attach**
3. On **GSuite Document** section select the Template and click **Attach**
4. You should see the generated document is already created and attached
5. Clicking on the attached document will open it inside Gsuite