Function #61: Automatically add free item to the invoice based on item quantity

Function #61: Automatically add free item to the invoice based on item quantity



Hello everyone, and welcome back to another Custom Function Friday!

During holiday seasons or special promotions, businesses offer deals like BOGO (Buy One, Get One), Buy 3 Get 1 Free, Buy 2 at 50% off, and much more to attract customers. These promotions encourage buyers to take advantage of limited-time offers, helping them save money while increasing foot traffic for businesses. In today's post, we’ll show you how to automate one such promotional offer – the 'Buy N items and Get X as free' using a custom function in Zoho Books.

Prerequisites: 

1. Create a Connection named "zbooks" to successfully execute the scheduler. You can watch the GIF attached below to know how to create the connection. 



2. Create a Lookup type custom field for Items. This field lets you choose the item to be given for free when a customer purchases a specified quantity of the same item. You can either select the same item as the free item or choose a different one.


3. Create a Check Box type custom field for Invoices. When creating an invoice, tick this field if you want to apply the offer to that particular invoice.




Custom Function:

Navigate to Settings -> Automation -> Workflow Actions -> Custom Functions -> +New Custom Function > Add the function code from this GitHub link -> Save. 



In line 10 of the script, you'll see the node "freeItemQTY". This is where you need to specify the minimum quantity a customer must purchase to qualify for a free item. For example, if the offer is Buy 5, Get 1 Free, then you would enter "5" here.

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.

Here's how it works:

Zylker Stationery has launched several promotional offers to boost sales during the back-to-school season. One of these offers is "Buy 6 Brushes, Get a Palette for Free." To implement this in Zoho Books, the first step is to designate the Palette as the free item associated with the purchase of Brushes in the Lookup custom field. The "freeItemQTY" node in the script should be set to 6.

When creating an invoice, the user must tick the checkbox custom field to apply the promotion, add the items, and save the invoice as a draft. Subsequently, the custom function will get executed,  automatically adding the Palette as a separate line item priced at zero. The updated invoice will then be sent to the selected customers.

If you’ve been running promotions like this and adding the free items manually every time you create an invoice, this function will really help save you time and effort! Give it a try and let us know how it goes. Additionally, we previously shared another function that automatically adds free items based on the invoice amount—be sure to check it out [here]. If you have any other use cases you'd like to automate in Zoho Books, drop an email to support[at]zohobooks[dot]com, and we can explore the possibilities.

Regards,
Shireen Farhana
Zoho Books


      • Recent Topics

      • Need Faster Help? Try Live Chat Support

        Hello there, We understand that sometimes, whether you’re facing an issue, exploring a feature, or need quick clarification, sending an email and waiting for a response just doesn’t cut it. You need answers, and you need them now. That’s exactly why we
      • Export History timeline

        Hi, I have an idea, bout zoho desk history of the ticket it would be great if the agent or admin of the zoho desk can export the timeline of the ticket history for agent report or on other matter.
      • How Do I Refund a Customer Directly to Their Credit Card?

        Hi, I use books to auto-charge my customers credit card. But when I create a credit note there doesn't seem to be a way to directly refund the amount back to their credit card. Is the only way to refund a credit note by doing it "offline" - or manually-
      • Desk fails to create a new ticket on Reply email

        When I send a direct email to support@mysite.com, Desk will create a new ticket as expected. When I REPLY to an email sent from support@mysite.com, Desk will NOT generate a new ticket. This is very bad. How can I fix this? Use case: In a separate system
      • Condition based aggregate fields in subforms

        Hello everyone, We're excited to inform you about the latest enhancements made to our aggregate field capabilities in subforms; create aggregate fields based on conditions! An aggregate field is a column on which a mathematical function has been applied.
      • Limitation with Dynamic Email Attachment Capture

        I've discovered a flaw in how Zoho Creator handles email attachments when using the Email-to-Form feature, and I'm hoping the Zoho team can address this in a future update. The Issue According to the official documentation, capturing email attachments
      • Ask the Experts 25: Experience the full spectrum of Zoho Desk’s autumn and spring releases for 2025

        Hello Everyone, We’re on the 25th episode of our ATE series! It's a true milestone in our live community interactions! It’s been an amazing journey since we started in October 2018. Zoho Desk has come a long way, evolving with the support of a wonderful
      • Addin Support in Zoho Sheet

        Is there any addin support available in zoho sheet as like google marketplace to enhance productivity by connecting with other apps, providing AI data analysis, streamlining business processes, and more?
      • Mass Update of Lookup Fields not possible

        Hello List I've created a custom field for Leads and Contacts 'Current Campaign'. This is very Handy as I can filter leads and then related them to a campaign. Everything ready, but then I realized that mass update doesn't work for lookup fields... a
      • Zoho Books | Product updates | November 2025

        Hello users, We’ve rolled out new features and enhancements in Zoho Books. From translating email notification templates to the new transaction locking restrictions, explore the updates designed to enhance your bookkeeping experience. Making Tax Digital
      • Function #61: Automatically add free item to the invoice based on item quantity

        Hello everyone, and welcome back to another Custom Function Friday! During holiday seasons or special promotions, businesses offer deals like BOGO (Buy One, Get One), Buy 3 Get 1 Free, Buy 2 at 50% off, and much more to attract customers. These promotions
      • TArgets To Accounts (Modules)

        How can i set sale target to Customers (Accounts Module)
      • Profit on Sales order

        Hi, would it be possible to implement a column at the Sales order overview of Purchase amount? So a field with the amount of all purchase related to this Sales order? This is very usefull so you will see the profit you made on this deal. I tried to get
      • Notes for Items for Future Purchase Order

        Next time when I order an item, tau have to make some changes in it, that order has to be placed after 4-5 months, I want to save those changes or points somewhere in the item, how will that be possible..
      • Schemes of different tyoe

        How can easily apply hourly, day wise or month wise  schemes on Bill, Quantity, and other schemes. Like I want to apply a scheme  Form today to next 7 days .where i can mention in zoho books so scheme will implement automatically to all customers and
      • Alphabetically

        How can i arrange alphabetically - (Manage Manufacturer) Field in Item Master 
      • Clients not receiving emails

        I've been informed that my emails are not being received. Is there anything that I should look into to rectify this? Many thanks!
      • Custom validation in CRM schema

        Validation rules in CRM layouts work nicely, good docs by @Kiran Karthik P https://help.zoho.com/portal/en/kb/crm/customize-crm-account/validation-rules/articles/create-validation-rules I'd prefer validating data input 'closer to the schema'
      • Contact data removes Account data when creating a quote

        Hi, Our customer has address fields in their quote layout which should be the address of the Account. They prefill the information, adding the account name - the address data is populated as per what is in the account - great. However when they then add
      • Enterprise subscription support

        My organization sells subscription services to enterprise customers, which is a different model from the consumer subscription model that Zoho Billing has been designed to support and I beleve this capability should be added. An enterprise subscription
      • Recruit paid support?

        Hi all, Could anyone who has paid support package advise if it provides value for money with regards to support response times? Exploring the idea as unfortunately when we have faced issues with Recruit it has been a 7+ day timescale from reporting to
      • Free Plan mail accounts details

        In the zoho mail pricing there's a free plan that includes: FREE PLAN Up to 25 Users 5GB* /User, 25MB Attachment Limit Webmail access only. Single domain hosting. I need to make sure that I'm able to create multiple email accounts in the form of: name@domain.com
      • ZOHO Mail App Not working

        There seems to be an issue with Zoho Mail App today. It is not connecting to server, internet is working fine, tried uninstalling app and reinstalling, loading circle keeps spinning round. Is there an update on the way?
      • No more IMAP/POP/SMTP on free plans even on referrals with NO NOTICE

        Outraged. Just referred a colleague to use her domain (not posting it publicly here) to Zoho, just as I have other colleagues, clients, friends. Expected the exact same free plan features as I have and as everyone else I ever referred got. I was helping
      • Unable to receive email - "5.3.0 - Other mail system problem 554-'5.2.3 MailPolicy violation Error delivering to mailboxes'"

        My users are unable to receive emails from one particular domain, apparently. The domain known to be kicked back is whitelisted in the spam control. I sent an email to support earlier this morning but I have not received a reply. The error in the title
      • Caixa de saída bloqueada. Como desbloquear?

        Olá, meu e-mail isabela.celli@sivirino.com está com a caixa de saída bloqueada. Não consigo enviar e-mails. Acredito que tenha sido porque mandei o mesmo e-mail para várias pessoas, pedindo uma cotação de serviço. Vocês podem desbloquear para mim? Quantos
      • Zoho Forms - Improve the CRM integration field to query data from more than one module

        Hi Forms team, Something I get stuck on regularly is pre-populating a form with data when that data is spread across 2 or 3 modules. For example Contacts, Accounts and Deals. I don't want to duplicate the information in CRM so I end up writing a function
      • desbloquear cuenta

        Buenos dias  Cordial saludo Tengo una cuenta libre en zoho mail asociado a un dominio, pero uno de los usuarios se bloquea el correo porque dice que ha excedido el límite de correo, por favor podrian desbloquearla y como hago para que esta persona debe enviar sus correos sin ningun probleama. Gracias de antemano
      • Reupload and rename from one field to another field (file upload)

        Hi Everyone, Sorry, i have question to use invoke url for rename and reupload attachments file to another field. Tested on development mode. Zoho C6. Refer to https://www.zoho.com/creator/help/api/v2/upload-file.html look my error notification. Does anyone
      • Not Receiving Incoming Mail

        I can send emails from my account but I do not receive any. I originally set up forwarding and it worked for a while and then stopped. I turned off forwarding and now do not receive any emails. Could you please check what is causing this issue? Thank you
      • Will zoho thrive be integrated with Zoho Books?

        title
      • BARCODE PICKLIST

        Hello! Does anyone know how the Picklist module works? I tried scanning the barcode using the UPC and EAN codes I added to the item, but it doesn’t work. Which barcode format does this module use for scanning?
      • Stock count by bin location

        Is there a configuration to make a stock count by bin or area and not by product. these is useful to manage count by area Regards
      • Making preview pane "stick"

        Hello, Is it possible to fix/dock the preview pane so that it's always there? The modern monitors are all very wide so there's plenty of space horizontally. Having the preview pane disappearing and appearing again when you click on an email message in
      • Introducing Multi-Asset Support in Work Orders, Estimates, and Service Appointments

        We’re excited to announce a highly requested enhancement in Zoho FSM — you can now associate multiple assets with Work Orders, Estimates, and Service Appointments. This update brings more clarity, flexibility, and control to your field service operations,
      • Reason:554 5.1.8 Email Outgoing Blocked

        I have been struggling to set up my email address for some time now; it's difficult to locate what I need. Additionally, I cannot send or receive any emails. I keep receiving the "Reason: 554 5.1.8 Email Outgoing Blocked" error. There doesn't seem to
      • Trouble Connecting Zoho Mail via IMAP in n8n – Need Help

        Hi everyone 👋, I'm trying to connect my Zoho Mail account to n8n using the IMAP Email Trigger node, but I'm facing issues getting it to work fully. ✅ Here's what I’ve done so far: ✅ IMAP access is enabled in my Zoho Mail settings ✅ I’m using the correct
      • Unable to send message; Reason:554 5.1.8 Email Outgoing Blocked

        Hi, I sent few emails and got this: Unable to send message; Reason:554 5.1.8 Email Outgoing Blocked And now I have few days since I cant send any email. Is there something wrong I did? Also can someone fix this please
      • Changes to the send mail Deluge task in Zoho CRM

        Hello everyone, At Zoho, we continuously enhance our security measures to ensure a safer experience for all users. As part of our ongoing security enhancements, we're making an important update on using the send mail Deluge task in Zoho CRM. What's changing?
      • Page Rules in Forms

        🚀 Dynamic Page Navigation Implementation I successfully implemented dynamic page navigation based on a user's radio button selection. The goal was to direct users to a specific, corresponding page while ensuring they only interact with the flow determined
      • Next Page