Function #28: Automatically calculate Customer Loyalty points
Hello everyone, and welcome back to our series! Today, we're excited to share a workflow designed to streamline the management of loyalty points.
Many businesses offer incentives or rewards in the form of loyalty points to their customers as a way to promote recurring business and build customer loyalty. These points are typically earned by making purchases, which customers can accumulate over time and then redeem for various rewards, such as discounts, free products, credit points, gift cards, or other perks.
Manually calculating the loyalty points for every customer's purchase can be a laborious and time-intensive process, particularly when you're managing a substantial customer base. But don't fret! Our custom function is here to save the day. The function will automatically calculate the loyalty points earned for each transaction and also generate a credit note once the specified limit is reached.
Here's how it works:
Whenever a customer makes a purchase and pays off the invoice in Zoho Books, the custom function gets executed. It calculates the loyalty points earned from that transaction and stores them in a custom field (created to accumulate the loyalty points). This process continues until the customer's loyalty point limit is reached. Then, the function automatically generates a credit note for the customer and resets their loyalty points. This credit note can be applied to the customer's next invoice, reducing the amount to be paid.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1699616173434.gif&blockId=edbsna0378837defa12e68189e989e258bb9c27ff10cc8fe1ca4867fe9be2656658d4&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
Prerequisites:
1. Create a
Connection named
"zbooks" to successfully execute the function. You can watch the GIF attached below to learn how to create the connection.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1699616269599.gif&blockId=edbsn67435e8ea179996c4d0fd0f370c67da4828a8ed7e427aad0b934c85f8aaf9c65&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
2. Create a Number type custom field named "Loyalty points" for the Customers module. This field will store the points earned by a customer.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1699616313622.png&blockId=edbsna0378837defa12e68189e989e258bb9c338e065fb8496dd8305f56925dcb8e70&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
Custom Function:
Navigate to Settings -> Automation -> Custom Functions -> +New Custom Function > Add the function code from this
GitHub link. Then, check and update the following variables as required.
1. minLoyaltyAmount - The purchase amount required for a customer to earn one loyalty point. For instance, if $500 spent equals 1 loyalty point, input 500 as the minLoyaltyAmount.
2. loyaltyFieldName - Copy and paste the API name of the custom field created in the Customers section to store loyalty points.
3. loyaltyLimit - Specify the limit to determine when loyalty points can be redeemed in the form of a credit note. For example, if a credit note should be generated when a customer accumulates 100 points, enter 100 as the loyaltyLimit.
Workflow Rule:
Go to Settings -> Automation -> Workflow Rules -> +New Workflow Rule and set up the workflow rule as shown below:-
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1699616536059.png&blockId=edbsn12b1d1894de272bec4ce0dd4e5dda102c822def995b0e2e8cf000dc0281bd56a&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1699616547505.png&blockId=edbsn41918ec3a27955aca61a1eb8c525c7b262ec00ad4b5091d219ce7f99ebca553e&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
In the final step of this workflow rule, associate the custom function you created and then hit Save.
Should you require any help in customizing this function to better suit your requirements, don't hesitate to reach out to us at support[at]zohobooks[dot]com. We will be happy to assist you!
Regards,
Shireen Farhana
Zoho Books