A noteworthy article in my opinion on how to send a CRM quote record using a template the customer created from a button.
Why?
Yes you can do this already by going to the record, clicking on the ellipsis or three horizontal dots button in the top right and selecting "Send Mail" then selecting which inventory template to use... This is too many steps for some. Instead, we've been asked to create a button that sits on the view page of a record and the staff simply click on and it does all the aforementioned.
How?
The difficult part here was to figure out how to convert the CRM record into a PDF using a customer's template.
// // initialize (this is code added to a button so should alert user if no email was specified) v_OutputMessage = ""; v_TemplateID = "123456789012345678"; // // get the quote details given a record ID r_QuoteDetails = zoho.crm.getRecordById("Quotes",p_QuoteID); // // check target email is not null/blank if(!isnull(r_QuoteDetails.get("Email"))) { v_Url = "https://zohoapis.com/crm/v2/settings/inventory_templates/" + v_TemplateID + "/actions/print_preview?record_id=" + p_QuoteID + "&print_type=pdf"; f_FileRequest = invokeurl [ url :v_Url type :GET connection:"zcrm" ]; f_FileRequest.setParamName("file"); f_FileRequest.setFileName(r_QuoteDetails.get("Subject") + ".pdf"); // // get a greeting name v_EmailTo = r_QuoteDetails.get("Email"); v_ContactName = r_QuoteDetails.get("Contact_Name").get("name"); v_EmailSubject = "Quote " + r_QuoteDetails.get("Subject") + " for " + r_QuoteDetails.get("Contact_Name").get("name"); v_EmailMessage = "Hi " + v_ContactName + ",<br /><br />Please find attached your quote.<br /><br />Kind Regards,<br /><br />The Team"; // sendmail [ from :zoho.loginuserid to :v_EmailTo subject :v_EmailSubject message :v_EmailMessage Attachments :file:f_FileRequest ]; } else { v_OutputMessage = "No email was specified on this record. Cannot send this quote."; } return v_OutputMessage;
- //
- // initialize (this is code added to a button so should alert user if no email was specified)
- v_OutputMessage = "";
- v_TemplateID = "123456789012345678";
- //
- // get the quote details given a record ID
- r_QuoteDetails = zoho.crm.getRecordById("Quotes",p_QuoteID);
- //
- // check target email is not null/blank
- if(!isnull(r_QuoteDetails.get("Email")))
- {
- v_Url = "https://zohoapis.com/crm/v2/settings/inventory_templates/" + v_TemplateID + "/actions/print_preview?record_id=" + p_QuoteID + "&print_type=pdf";
- f_FileRequest = invokeUrl
- [
- url :v_Url
- type :GET
- connection:"zcrm"
- ];
- f_FileRequest.setParamName("file");
- f_FileRequest.setFileName(r_QuoteDetails.get("Subject") + ".pdf");
- //
- // get a greeting name
- v_EmailTo = r_QuoteDetails.get("Email");
- v_ContactName = r_QuoteDetails.get("Contact_Name").get("name");
- v_EmailSubject = "Quote " + r_QuoteDetails.get("Subject") + " for " + r_QuoteDetails.get("Contact_Name").get("name");
- v_EmailMessage = "Hi " + v_ContactName + ",<br /><br />Please find attached your quote.<br /><br />Kind Regards,<br /><br />The Team";
- //
- sendmail
- [
- from :zoho.loginuserid
- to :v_EmailTo
- subject :v_EmailSubject
- message :v_EmailMessage
- Attachments :file:f_FileRequest
- ];
- }
- else
- {
- v_OutputMessage = "No email was specified on this record. Cannot send this quote.";
- }
- return v_OutputMessage;
Update: What is the URL to download the PDF in Zoho Books?
Found this today so thought I'd add it to this article:
- Invoice: https://books.zoho.com/api/v3/invoices/pdf?organization_id=<Zoho_Books_Org_ID>&invoice_ids=<Zoho_Invoice_ID>
- Invoice [Alt]: https://books.zoho.com/api/v3/invoices/<invoice_ID>?accept=pdf&organization_id=<Zoho_Books_Org_ID>
- Bill: https://books.zoho.com/api/v3/bills/<bill_ID>?accept=pdf&organization_id=<Zoho_Books_Org_ID>
Caveat(s):
- The "From" email address can only be the admin or the logged-in user (user who clicks on the button).
- There might be an easier way to get the template ID used in CRM, but we did this by
- Login to ZohoCRM > Settings > Templates > Inventory
- Hover the mouse cursor over the template you want to use.
- Note or screenshot the url that pops up and the template ID is at the end of it.