Businesses often need to send quotes, sales orders, and invoices to customers via email as attachments. Using a workflow rule to send these documents attached to an email template automatically can improve efficiency. However, the existing version of workflow automation limits the ability to send email attachments of varying files. What if there were a quick workaround that accomplishes the above? Our low-code solution offers an effective workaround.
Using functions, you can send emails containing record-specific attachments through a workflow rule. For example, upon creating an invoice, you can automatically send it as a PDF attached to an email. All you need to do is create an email template, specify its ID in the function, and then send the file as an attachment via a workflow rule.
Permissions and availability
- Users with Manage Extensibility permission can create connections and write custom functions.
- Users with Manage Templates permission can create and update inventory templates.
- Users with Manage Automation permission can create and update workflow rules.
- Users with Manage Sandbox permission can manage the sandbox.
Requirements
- Create a Zoho OAuth connection with the required scopes for your Zoho CRM account, as detailed in the "Create Connection" section below. Learn more
- Create a custom inventory template for the Invoices module to send invoices. Learn more
- Create a workflow rule for the Invoices module that triggers every time an invoice is created. Learn more
- Write a custom Deluge function that sends invoices to the contact's email address and link it up with the workflow rule. Learn more
- Test the workflow rule in a sandbox before deploying it to your production environment. Learn more
Create a connection
The first step is to create an OAuth connection in your Zoho CRM account.
- Navigate to Setup > Developer Space > Connections.
- Click Create Connection.
- Select Zoho OAuth under Default Services.
- Specify a Connection Name.
You will need to enter this name in the code snippet below. - Select the following Scopes to request access.
- ZohoCRM.modules.all
- ZohoCRM.settings.all
- ZohoCRM.templates.inventory.READ
- Click Create and Connect.
- Click Connect, then click Accept to confirm authorization of access for the scopes requested by the client.
Create an invoice template
The next step is to add the custom invoice template to be shared with your customers.
- Navigate to Setup > Customization > Templates > Inventory > +New Template.
- Select Invoices from the dropdown list, then click Next.
- Choose Blank in the Template Gallery to create a template from scratch, or select a pre-built invoice template and customize it using the drag-and-drop editor.
- Once finished, click Save Now and copy the template's ID from the address bar, which you must enter in the code snippet below.
Create a workflow rule
The final step is to create a workflow rule and connect it with a custom function.
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select the Module as Invoices from the dropdown list.
- Provide a name for the rule. For example: "Send invoice as email attachment".
- Add a description, if required, then click Next.
- In the Execute this workflow rule based on section, choose Record Action, then select Create from the dropdown and click Next.
- In the Which invoices would you like to apply the rule to? section, select All Invoices and click Next.
- Under Instant Actions, select Function and Write your own.
- Provide a name for the function, as well as a description, if necessary.
- In the Deluge Script Editor, do the following:
- Copy and paste the code provided below.
- Click Edit Arguments.
- Choose Invoices - Invoice Id, then name it invoiceId.
- Click the + icon to add more arguments.
- Choose Contacts - Email, then name it email.
- Click Save, then click Save & Execute Script.
- Click Save on the workflow rule page.
The code
tempid = "xxxxx";
fileUrl = "https://www.zohoapis.com/crm/v2/settings/inventory_templates/" + tempid + "/actions/print_preview?record_id=" + invoiceId + "&print_type=pdf";
invoiceFile = invokeurl
[
url :fileUrl
type :GET
connection:"connectionname"
];
sendmail
[
from :zoho.adminuserid
to :email
subject :"Here is your zStore invoice"
message :"Dear Customer! Please find the attached invoice for your recent purchases from zStore. Regards, Jim."
Attachments :file:invoiceFile
]
Notes
- Replace "xxxxx" with the ID of the invoice template. (see the "Create an invoice template" section above).
- As the API URLs differ for each data center, you should identify your account's data center and use the corresponding domain in the fileUrl. For example, for India, use https://www.zohoapis.in/crm.
- Replace "connectionname" with the name of the connection you specified while creating the connection (see the "Create a connection" section above).
- Customize the email subject and message body in lines #13 and #14, respectively.
- The code above is an example of sending PDFs of invoices as email attachments using a workflow rule. You can use this code for any other module, such as quotes, sales orders, and purchase orders, by modifying the module name and other parameters.
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to Invoices > +Create Invoice.
- On the Invoice Details page, enter the contact name and other invoice information, then click Save.
The workflow rule will be triggered. - Check whether the contact's email address receives the email with the specified subject, message, and PDF of the invoice as outlined in the function.
Limitations
- The emails will be sent (i.e., from address) using the email address of the primary account owner in your CRM.
- If the total size of the attachments exceeds 10MB, the function will not send the email when creating an invoice.
- Since the emails are sent from the Deluge server rather than through your CRM's IMAP integration, they will not show up on the invoice's Emails Related List.
- The PDF file sent via email is automatically named using a random combination of numbers, such as 1234567890.pdf, and cannot be modified while sending.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleInvoices
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityHigh
- Implementation Time60 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST