We’re Heading to CNX ’25. Let's Meet in Chicago! Join HIC at Salesforce Connections'25 for conversations, collaboration, and co-creation.

Salesforce CPQ plugins are custom extensions that add functionalities to the existing CPQ application. These plugins are written in JavaScript and can be used to perform complex calculations, validations, and custom logic that go beyond the standard CPQ capabilities.

Custom scripts in Salesforce CPQ are like building blocks that enable you to organize and reuse blocks of code for various functionalities. Unlike specific rule-based components, custom scripts contain code that can be utilized in multiple contexts throughout the CPQ application.

In particular, calling a custom script within the Quote Calculator Plugin is a game-changer, as it allows you to influence how the quote calculator processes data to generate accurate quotes. Whether you wish to apply an additional discount to specific line items on the quote or alter field visibility, custom scripts give you the flexibility to make these adjustments.

Understanding Quote Calculator Plugin Methods:

In Salesforce CPQ, the Quote Calculator Plugin offers a set of methods that you can utilize to customize the pricing and calculation process. Here are the available methods:

  1. Oninit: This method is executed before formula fields are evaluated. It provides a suitable starting point for any pre-calculation tasks.
  2. OnbeforeCalculate: The calculator calls this method before the actual calculation begins, but after formula fields have been evaluated. It’s a great place to perform any preparatory actions before the real calculations kick in.
  3. OnbeforePricerules: This method is called before the price rules evaluation process. Utilize it to set up the stage before applying pricing rules.
  4. OnafterPricerules: Following the price rules evaluation, this method is executed. Use it to implement any custom logic based on the price rules’ outcomes.
  5. OnafterCalculate: Once the calculation process is complete, but before re-evaluating formula fields, this method is triggered. It’s a convenient spot for post-calculation tasks.
  6. IsfieldEditable: This method is called after the calculation process. Use it to control the editability of specific fields based on your custom logic.
  7. IsfieldVisible: Also triggered after the calculation process, this method is perfect for managing field visibility based on custom conditions.

Steps To Call a Custom Script in the Quote Calculator Plugin:

Step 1: Click on App Launcher —> Quick find box —> Custom Script

Untitled 2 7529016f84

Step 2: On the Custom Script List view page click on New Button.

Untitled 3 75291f312b

Step 3: In the New custom script window add:

  • Name in the Script Name field.
  • JS script in the Code field.
  • Quote Fields used in JS script in Quote Fields with comma separated.
  • Quote Line Fields used in JS script in Quote Line Fields with comma separated for

Note: Add API name of fields used in JS script only. Also, if any Quote Line Group Field is used in your JS script add them also in the respective column.

Untitled design 1

Step 4: Click on Save.

Hurray!! you have just created your first custom script. Now it’s time to add it on the calculator plugin in.

Step 5: Click Setup —> Quick find box —> Installed Packages

Untitled 5 752954797d

Step 6: From the Installed Packages list click on Configure next to Salesforce CPQ Package.

Untitled 1 75308a6288

Step 7: The setting Editor window will open from there Click on Plugins.

Untitled 6 7530981a35

Step 8: Add the name of your custom script in the Quote Calculator Plugin field and then click on Save Button.

Untitled 7 753105af3e

Note:  You can create multiple custom script but you can add only single custom script in Plugin. Create multiple method in single custom script make it perform multiple task.*

Hurray!! You have have successfully added you custom script in Calculator Plugin.

Use Case Scenario:

Account related to Quote have closed won opportunities and total amount of those opportunities is amount > 500, apply 5% discount on each quote line amount > 1000, apply 10% discount on each quote line amount > 2000, apply 20% discount on each quote line Also, if we edit discount of any quote line and the edited discount is less than our initial given discount then apply less discount but, if edited discount is greater than initial discount then apply initial discount only.

For above case custom script code:

Configure Test:

  • Go to Quote and create a quote or open an existing Quote.
  • Click on Edit Lines and add Products.

Note: This script will only run when an account related to your quote has closed won opportunity and the amount is greater than 500.

  • In this image you can see a Discount get applied to all quote lines according to our script as the account related to this quote has closed a won opportunity whose amount totals> 500.

Untitled 8 75335410d3

  • In this image, we have edited the discount in two quote lines

Untitled 9 7533695967

  • In this image, you can see as per our script discount 4 is applied in a particular quote line item, but in place of 6, our initial discount 5 gets applied for that quote line item.

Note: Discount will reflect when clicking on the Calculate Button on the Quote Line Editor page.

Untitled 10 1

Conclusion

Custom scripts in Salesforce CPQ plugins, especially within the Quote Calculator Plugin, bring a new dimension of customization and efficiency to your quoting processes. They allow you to create tailored functionalities, streamline calculations, and enhance user experiences.

With custom scripts by your side, your Salesforce CPQ plugins become an invaluable asset that aligns with your business goals, empowering your sales team to excel, exceed customer expectations, and drive growth like never before.

So, go ahead and embrace the limitless possibilities of custom scripts, and unlock the full potential of your Salesforce CPQ plugins today. And for more blogs, stay tuned!

Related Articles
How to Use Platform Events in Salesforce Flow for Real Time Updates

Platform events in Salesforce Flow are a great tool for creating real-time, event-driven apps that automate business operations with precision and speed. By integrating Platform Events’ publish-subscribe approach with Salesforce Flow‘s low-code features, you can automate processes, allow real-time system interaction, and optimize how your organization manages dynamic data changes. This guide will demonstrate how […]

Read More
Build a Dynamic Salesforce Data Viewer with hange kardo bas LWC

Lightning Web Components (LWC) is a modern JavaScript framework that is used for building responsive, dynamic applications on the Salesforce platform. In LWC, data flows from parent-to-child component. Variables marked as @api in the child component are open for a parent to pass values directly into the child’s HTML template, making the component interactable. To […]

Read More
Expert Guide On Nominal XIRR Calculation Using LWC in Salesforce

When building financial tools within Salesforce, handling irregular cash flows with precision is a must. Whether you’re developing investment trackers, portfolio performance dashboards, or funding monitors, calculating Nominal XIRR (Extended Internal Rate of Return) becomes essential. In this blog, you’ll learn how to build a Lightning Web Component (LWC) in Salesforce that calculates Nominal XIRR […]

Read More
Beginners Guide to Making Your LWC Component Multilingual

If you’re wondering how to make your LWC component multilingual, you’re already ahead of the curve. Global users expect content in their native language, and Salesforce gives you the tools to deliver exactly that. With Custom Labels and the Translation Workbench, you can easily localize your Lightning Web Components without touching a single line of […]

Read More
Hands-On Guide Building a Drag-and-Drop Form Builder Using Lightning Web Components

Drag-and-drop interfaces are a user experience staple, and when paired with the power of Lightning Web Components (LWC), they unlock dynamic, highly interactive Salesforce components. In this blog post, we’ll walk you through how to build a custom drag-and-drop form builder in LWC. Users can drag form fields like text inputs and dropdowns into a […]

Read More
Please Make Blog Banner How to Create an Agentforce Enabled Scratch Org in Salesforce 100 1

Setting up an Agentforce-enabled scratch org is the most important step for developers who want to experiment with AI features such as Prompt Builder and Einstein GPT. Whether you’re developing the next generation CRM software or experimenting with how generative AI may improve user experience, a scratch org equipped with Agentforce is your playground. Follow […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
6D - 7398 Yonge St #1124 Thornhill, ON L4J 8J2 Canada +1(262) 310-7818