Function 33#: Associate invoice templates automatically based on customer address

Function 33#: Associate invoice templates automatically based on customer address



When a business deals with customers across various countries, there may arise a need to have different templates applied which caters to the customer's country specific billing requirements.

While we do allow users to associate the required templates to the customers manually, it could get tedious over time as your business expands.

For this scenario, you can build all the invoice templates with each country’s specification and name each template after the corresponding country.

Today’s custom function will then help you automate the
appropriate invoice template selection at customer level based on the primary billing country of the customer. 

Here's how the custom function will work:
 
Once you create a customer profile with a billing address and save the customer, this custom function will be executed. The function will check for the billing country chosen in the customer's address and automatically associate the corresponding template to the customer.

You can then cross-check the template applied by heading over to Sales >> Customers >> Click on the customer profile  >> More >> Associate templates. The template that is automatically selected for 'Invoices' there will be applied for the future invoices of that particular customer by default.

Pre-requisites:

1. Create a Connection named "zbooks" to successfully execute the function. You can watch the GIF attached at the bottom of this post to learn how to create the connection.

2. Create invoice templates for each billing country and label each template according to its respective country.


Lets say, you're designing a template for a customer based out of Singapore, the template in this case should be named "Singapore".

Custom Function:
 
Navigate to Settings -> Automation -> Custom Functions -> +New Custom Function > Add the function code from this GitHub link.
 
Workflow Rule: 
 
Go to Settings -> Automation -> Workflow Rules -> +New Workflow Rule and set up the workflow rule as shown below:-







In the final step of this workflow rule, associate the custom function you created and then hit Save.

The script shared works for the Invoice template selection based on customer address and we hope this automation takes you one step further in fine-tuning your business workflow.

Should you need assistance in configuring a similar workflow for any other module, do reach our support desk. We will be available to help you.

Regards,
Archana Puthumana
Zoho Cares