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:

Want to learn even more?
Sign up for one of our Zoho courses!

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

Want to learn how to create Invoice and collect payment from Zoho Creator?

Or learn how complex assignment rules config Via Zoho CRM modules works?

Want this functionality, but don't want to do it yourself?

Click here to speak to us!

Need help with your Zoho system?

Hire a full time Zoho System Admin from our poolof highly qualified program graduates!

Related Resources