Auto-apply product discounts

Automatically apply category-based discounts to products or services when selected in the quote subform of your CRM.

Are you a B2B seller where each product category has its own pricing margins and discount policy? Does your sales team create quotes for bulk orders spanning multiple product categories with preset discount logic? Or do you want to spend less time assembling quotes and more time selling and engaging with customers? Regardless of your situation, automating the application of discount logic ensures that every product in the line item receives the correct category-specific discount without requiring manual entries.

The benefits? Your sales team can quote faster, eliminate discount errors, and improve overall turnaround time. However, if you take a cursory look at your CRM, you could find that the built-in automations do not support auto-applying a discount to line items in quotes. Fortunately, our low-code tools can make it possible.

Using a combination of a custom field and a client script, you can automatically apply category-based discounts to products or services when selected in the quote subform. You simply need to define the discount percentage for each product category. Read on to learn more.

Permissions and availability

  • Users with the Modules Customization permission can add custom fields.
  • Users with the Manage Extensibility permission can create client scripts.
  • Users with the Manage Sandbox permission can manage the sandbox.

Requirements

  • Add a Pick List field to the Products module. This field will contain the different product categories your business offers and should be associated with individual products. Learn more
  • Create a client script that triggers whenever you update any value in the quote's subform cell. Learn more
  • Test the function in a sandbox environment before deploying it to your production environment. Learn more

Add a custom field

The first step is adding the custom pick list field to the Products module.

  1. Navigate to Setup > Customization > Modules and Fields.
  2. Click the Products module to open the layout editor.
  3. Drag and drop the Pick List field from the New Fields tray to the desired section of the layout.
  4. Name the pick list field (e.g., "Scope"), enter the options (e.g., "Kitchen Appliances", "Cleaning Appliances", etc), and define its properties as required.
  5. Once you have finished, select Done, then click Save and Close.

Create a client script

The next step is to create a client script in your Zoho CRM account:

  1. Navigate to Setup > Developer Hub > Client Script > +New Script.
  2. Provide a name for the script. For example: "Auto-apply product discounts".
  3. Add a description (optional).
  4. In the Category Details section, do the following:
    1. Category - Choose Module.
    2. Page - Choose Create Page.
      You may also need to add the script for the Edit Page.
    3. Module - Choose Quotes.
    4. Choose the layout.
      It can be Standard or any other custom layout of the quotes module.
  5. In the Event Details section, do the following:
    1. Type - Choose Subform Event
    2. Field - Choose Quotes Items
    3. Event -  Choose onCellChange.
  6. Click Next.
    The Client Script IDE will open.
  7. Copy and paste the script provided below.
    You can customize the script, if needed.
  8. Click Save and Close to save the client script.

The code

Code Copied
console.clear();
console.log("start");
console.log("value : ", value);
var subform = ZDK.Page.getSubform("Quoted_Items").getValues();
console.log("subform : ", subform);
if (field_name == 'Product_Name')
{
    var val = value.id;
    var amount = ZDK.Page.getSubform("Quoted_Items").getRow(index).getCell("Total").getValue();
    console.log("amount : ", amount);
    log("Product:" + JSON.stringify(val));
    var product = ZDK.Apps.CRM.Products.fetchById(val);
    var scope = product.Scope;
    var dis = 0;
       if (scope == "Kitchen Appliances")
    {
        var dis = amount * 30 / 100;
    }
       if (scope == "Cleaning Appliances")
    {
        var dis = amount * 25 / 100;
       }
       if (scope == "Home Automation")
    {
        var dis = amount * 10/ 100;
    }
       if (scope == "Food Preparation")
    {
        var dis = amount * 35 / 100;
      }
       if (scope == "HVAC Appliances")
    {
        var dis = amount * 20 / 100;
    }
       if (scope == "Office Appliances")
    {
        var dis = amount * 20 / 100;
      }
       if (scope == "Installation Services")
     {
        var dis = amount * 0 / 100;
       }
    console.log("dis : ", dis);
    ZDK.Page.getSubform('Quoted_Items').getRow(index).getCell('Discount').setValue(dis);
}

Notes

  • Make sure you update the script with the accurate API name of their corresponding fields (e.g., "Scope"). Learn more
  • Customize the seven product categories in the above script (e.g., "Kitchen Appliances", "Cleaning Appliances", etc.) according to the pick list options in the product record. You can also add or remove them as needed.
  • Customize the default discount (e.g., "var dis = amount * 30 / 100;") for each product category in the script so it applies automatically when a product is selected.
  • You may also need to include the script on the Edit and Clone pages to ensure that any product updates receive their default discount.
  • The above script is an example of how to automatically apply category-based default discounts to products added in quote subforms. You can use this client script for any other module, such as Deals or custom modules, by modifying the module name and parameters.

Tip

  • Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.

Test the solution

  1. Navigate to Quotes > +Create Quote.
  2. On the Quote Details page, enter the required information, including the product name and amount in the Quoted Items subform.
    The client script will be triggered.
  3. Check whether the Discount field in the product line item reflects the correct discount amount based on the percentage specified in the client script.
  4. Select different products to check whether the appropriate discounts are applied.

Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.

More info

  • ModuleQuotes
  • Trigger PointBrowser
  • EditionEnterprise and above
  • ComplexityMedium
  • Implementation Time30 minutes

Features used in the solution

Custom FieldClient ScriptSandbox
Story Image

Looking for a custom solution?

Contact us, we will help enhance your productivity at lightning speed.

SUBMIT REQUEST

Developers: Share your solution with our community!