Automated Invoice Creation via Zoho CRM
- Peter
- Difficulty: Beginner
- Estimated reading time: 15 mins
Like many of our posts that link back to our GitHub page, here’s a specific use case with limitless customizability.
Think about your sales process as currently laid out in Zoho CRM. Leads come in, they talk to a salesperson, they progress through the pipeline until they are ready to sign a contract or make a purchase.
Now, how nice would it be if you could, at the press of a button, send that client an email w/a Zoho Books invoice? Replete with “Pay Now” buttons that link to PayPal/Stripe/other payment gateways?
If you like this, you’ll probably love our other Zoho training resources (they’re free!).
A quick point to note — this integration works OUTSIDE of the boundaries of the CRM-Books integration. You can still have the CRM-Books integration set up and use this code, but it’s not necessary to have it enabled.
The CRM-Books integration DOES have an automated invoice creation tool, but we’ve seen the following problems with it:
Click this link from our GitHub to see our code.
The code starts similar to most other functions we write. We query the information we want from the Contact record and define the variables we will use later in the function (name, email, etc.).
Next, comes a Zoho-defined API call. Almost all commands in the Zoho Finance Suite require an “Organization ID”, so we use this to query that for later use. We learned this from the Zoho Books API Doc.
Next, a quick search of the Customers module (API name of “contacts”, yes, it’s confusing lol) for customers with the same email as our CRM Contact.
If it finds a Customer with that email, we attach the Invoice to that Customer and pull the Contact Person information for our email.
If our search turns up empty (i.e. there is no Customer record in Books that matches that email) we first create that record before pulling the Contact Person information for the Invoice. This is the “if…else” code from lines 23-56.
Next, we create the map to populate the Invoice. Put in the Contact Person’s information, the invoice line items, and the payment options. More details on the actual Invoice creation is found here.
Quick note: if you created custom fields for your invoice and have trouble adding them to a record (like we did), look at our other Zoho Books Custom Fields repository for help.
To finish up, use the zoho.books.createRecord command to create the Invoice. Then, if created correctly, the last API call (seen below) sends off the email! Note how you need to customize the URL on the second line down with the invoice AND organization ID’s.
Trigger this function using a workflow rule or create a custom button to fire it when you want.
Again, here is the link to the code and to the Workflow Academy GitHub page.