Google GSuite
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
1.1 Publish Google apps script
If you will use the default script you can go to 1.2
- Go to https://script.google.com
- Create a new Project. Click on File > New > Project
- Copy the code of Desk > Explore > Integrations > GSuite Settings > Google Apps Script to clipboard and paste to an empty Code.gs in script.google.com
- Save the Project. Click on File > Save > Enter new project name
- Deploy the app. Click on Publish > Deploy as web app
- Copy "Current web app URL" into Desk > Explore > Integrations > GSuite Settings > Script URL
- Click on OK but don't close the script
1.2
1.2 Get Google access
- Go to your Google project console and select your project or create a new one. https://console.developers.google.com
- In Library click on Google Drive API and Enable
- Click on Credentials > Create Credentials > OAuth Client ID
- Fill the form with:
- Web Application
- Authorized redirect URI as
http://{{ yoursite }}/?cmd=frappe.integrations.doctype.gsuite_settings.gsuite_settings.gsuite_callback
- Copy the Client ID and Client Secret into Desk > Explore > Integrations > GSuite Settings > Client ID and Client Secret
- Save GSuite Settings
1.3 Test Script
- 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://
orhttps://
matches the one your using. - Click on Run Script test. You should be asked to give permission.
2. GSuite Templates
2.1 Google Document as Template
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 DoctypeFor 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}}
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 is1Y2_btbwSqPIILLcJstHnSm1u5dgYE0QJspcZBImZQso
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 is0BxmFzZZUHbgyQzVJNzY5eG5jbmc
2.2 Associate the Template to a Doctype
- Go to Desk > Explore > Integrations > GSuite Templates > New
- 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
)
- Template Name (Example:
3. Create Documents
- Go to a Document you already have a Template for (Example: Employee > John Doe)
- Click on Attach File
- On GSuite Document section select the Template and click Attach
- You should see the generated document is already created and attached
- Clicking on the attached document will open it inside Gsuite