Automated Invoice Creation from Zoho CRM

Automating Zoho Books Invoice Creation + Emailing From Zoho CRM

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 Note on the Zoho Books-Zoho CRM Integration

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:

  • It only can trigger when a Deal reaches a certain Stage. If you want invoices to trigger from any other module/field, this doesn’t work.
  • It doesn’t auto-email the invoice

Does This Work With Zoho Invoice?

In a word — yes! You’ll just have to change the API calls, connections, and “zoho.books” built-in Deluge connections. Besides that, the code will work perfectly w/Zoho Invoice.  

Connecting Books and CRM

If you haven’t ever created a connection (not to be confused with integration) between Zoho CRM and another Zoho app, watch the below video:

Walking Through the Code

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.

How Do I Select Items for My Invoice?

This function assumes that you’re just hard-coding in a line item ID (e.g. “Service Fee”). If you’re not doing that, here are a few other options:
  • If you have 1000s of Products to choose from, sync your Products from Books to CRM.
    • Create a subform with a lookup to the Products module.
    • For each product, do a lookup based off SKU to find the Books item ID and then add it to your Invoice.
  • If you only have 10-20 items, add their SKUs to a multi-select picklist and use those SKUs in a searchRecords function to find the Books ID.

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

100+ lines of code?! What if I can't implement this on my own???

You’re probably not alone in thinking this. And, you have a million other things you specialize in and need to focus on. 

If this is the case, click the button below to learn how we can help you. With years of experience fine-tuning our Zoho skills, chances are we can build whatever you require!

And if your need or project is not a good match for our skill set, we can match you with the right person in our extensive Zoho network.

Some Link or other Offer, CTA

If you have any brains at all, you would take us up on this offer
$599 Value

Deluge Tips – Null Check

When scripting, ask yourself this question – will this value ever be null? If it’s a yes, that’s a place for a null check! Here are 3 tips and best practices to help you kickstart the habit.

Read More »

Invoice to Serialized Equipment

This tutorial will illustrate how to create a custom function (using Deluge scripting) where when an Invoice is submitted in Zoho Books, an Equipment record is created in Zoho CRM that tracks which specific units a customer owns.

Read More »