Does your business provide different discount rates for each product line? Have your salespeople offered excessive discounts to close deals that have impacted your margins? Are you aiming to enforce pricing discipline across products and teams? Regardless of your case, without a reliable automation system that enforces discount limits by the product line, salespeople can override pricing rules without approval.
You might consider using validation rules, but they can't loop through subforms or dynamically fetch product category details during validation. Workflow rules can only flag records, rather than stopping them from being saved. Built-in automation tools can't manage this type of validation flexibility; fortunately, custom functions can.
In such circumstances, you can use our low-code tools to automatically validate discount rates. Using a combination of a custom field and a client script, you can smoothly execute these automations on your browsers whenever you save a quotation in your CRM. 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 lines 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.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Products module to open the layout editor.
- Drag and drop the Pick List field from the New Fields tray to the desired section of the layout.
- Name the pick list field (e.g., "Scope"), enter the options (e.g., "Kitchen Appliances", "Cleaning Appliances", etc), and define its properties as required.
- 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:
- Navigate to Setup > Developer Hub > Client Script > +New Script.
- Provide a name for the script. For example: "Validate product discounts".
- Add a description (optional).
- In the Category Details section, do the following:
- Category - Choose Module.
- Page - Choose Create Page.
You may also need to add the script for the Edit Page. - Module - Choose Quotes.
- Choose the layout.
It can be Standard or any other custom layout of the quotes module.
- In the Event Details section, do the following:
- Type - Choose Subform Event
- Field - Choose Quotes Items
- Event - Choose onCellChange.
- Click Next.
The Client Script IDE will open. - Copy and paste the script provided below.
You can customize the script, if needed. - Click Save and Close to save the client script.
The code
console.clear();
console.log("start");
var subform = ZDK.Page.getSubform("Quoted_Items").getValues();
var save = true;
if(subform.length>0)
{
for (i=0; i<subform.length; i++)
{
var productID = subform[i].Product_Name.id;
var product = ZDK.Apps.CRM.Products.fetchById(productID);
var scope = product.Scope;
var amount = subform[i].Total;
var discount = subform[i].Discount;
var maxDiscount = 0;
var checkDiscount = false;
if (scope == "Kitchen Appliances")
{
var maxDiscount = 0.3;
var checkDiscount = true;
}
if (scope == "Cleaning Appliances")
{
var maxDiscount = 0.3;
var checkDiscount = true;
}
if (scope == "Home Automation")
{
var maxDiscount = 0.1;
var checkDiscount = true;
}
if (scope == "Food Preparation")
{
var maxDiscount = 0.35;
var checkDiscount = true;
}
if (scope == "HVAC Appliances")
{
var maxDiscount = 0.2;
var checkDiscount = true;
}
if (scope == "Office Appliances")
{
var maxDiscount = 0.25;
var checkDiscount = true;
}
if (scope == "Installation Services")
{
var maxDiscount = 0;
var checkDiscount = true;
}
if(checkDiscount == true)
{
if(discount > maxDiscount*amount)
{
ZDK.Client.showAlert('Discount exceeds allowed limit for this product category.');
var cell_obj = ZDK.Page.getSubform('Quoted_Items').getRow(i).getCell('Discount').showError('Discount should not be more than ' + (maxDiscount*100).toString() + '%');
var save = false;
break;
}
}
}
}
if(save == false)
{
return false;
}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 line items 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 per requirements.
- Customize the maximum allowed discount (e.g., "var maxDiscount = 0.3;") for each product line in the script to trigger alerts whenever the limit is exceeded.
- You may also need to include the script for the Edit and Clone pages to ensure that any quantity updates are validated.
- The above script is an example of validating product discounts entered in subforms based on their product line to ensure they do not exceed allowed thresholds. You can use this client script code 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
- Navigate to Quotes > +Create Quote.
- On the Quote Details page, enter the required information, including the product name and discount percentage in the Quoted Items subform.
The client script will be triggered. - Check if any alerts are triggered when interacting with the subform.
- Enter different products and discount percentages to check if alerts are displayed when they do not comply with the maximum allowed discount rules defined for the corresponding product.
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

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST