There are circumstances when you’d like to email PDF attachments but your workflow requires a function. Zoho has no native HTML to PDF conversion facility, but this can be solved using a 3rd party HTML to PDF converter and the CRM functions, toFile and attachFile. Here is a code snippet that demonstrates this.
html = "<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>";key = "myAPIKey";headers = map();headers.put("Content-Type","application/json");dataMap = map();dataMap.put("key",key);dataMap.put("html",html);tCustomer = zoho.crm.getRecordById("TCustomers", ###############);result = invokeurl[ url: "https://api.easypdfserver.com/make-pdf" type: POST parameters: dataMap.toString() headers: headers];resp = zoho.crm.attachFile("TCustomers", tCustomer.get("id"), result);info resp;sendmail[ from: zoho.loginuserid to: zoho.loginuserid subject: "test attachment" message: "we are testing attachments" Attachments :file:result]
In the above example I am making use of EasyPDFServer to perform the HTML to PDF conversion. Once I get the file (result) it’s simply a matter of saving the attachment and then attaching it to an outgoing email. If you are concerned about storage, don’t save the attachment to a module.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.
Leave a Reply