Loading
Manage Your Quotes with CPQ
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Custom Scripts for Discounting Consumption Rates

          Custom Scripts for Discounting Consumption Rates

          Custom scripts can add extra functionality to the quote line editor. Review the sample script to learn how to use JavaScript to apply discounts to selected consumption rates on a consumption schedule. (Salesforce CPQ Managed Package)

          Required Editions

          Available in: Salesforce CPQ Winter ‘19 and later

          To create or modify custom scripts, users require the Customize Application permission.

          Javascript Quote Calculator plugins don't support custom fields on consumption rates and consumption schedules.

          When a user manually changes a field value that was set by a Quote Calculator plugin, the system prioritizes the value calculated by the plugin and overwrites the value that the user manually entered.

          Example
          Example

          This custom script uses a custom quote field called UbpDiscount__c.

          Name
          UBP Discount
          Quote Line Fields
          UbpDiscount__c
          SBQQ__Price__c
          Code
          export function onBeforeCalculate(quote, lines, conn) {
                  if (lines) {
                     lines.forEach((line) => {
                      const ubpDiscount = line.record['SBQQ__UbpDiscount__c'];
                      if(ubpDiscount) {
                        if (line.consumptionSchedules) {
                             line.consumptionSchedules.forEach((cs, index) => {
                                  const rates = cs.getRates();
                                  if (rates) {
                                       rates.forEach((rate, index) => {
                                            const originalPrice = rate.get('SBQQ__Price__c');
                                            // Provide 10% discount
                                            const newPrice = originalPrice* 0.9;
                                            rate.set('SBQQ__Price__c', newPrice);
                                       });
                                  }
                             });
                        }
                      } 
                    });
                  }
            return Promise.resolve();
          }
           
          Loading
          Salesforce Help | Article