Loading
Get Started with Communications, Media, and Energy & Utilities (CME)...
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
          Overriding Default Functions

          Overriding Default Functions

          To override default JavaScript functions, the descendant class can override certain behavior in the ancestor class by specifying the modified behavior in protected methods (similar to the object-oriented technique of Java protected methods).

          Note
          Note

          For details about adding pre- and post-processing logic, see Adding Pre- and Post-Processing Logic.

          This mechanism enables customers to override a function of the default JavaScript controller. The function must meet the following criteria:

          • The function must be a scope function, that is, $scope.function.

          • The function must be defined in the allowlist. Using an allowlist avoids abusive overrides of key functionality.

          You can override the following controllers:

          Controller

          Functions

          CPQPromotionItemController

          $scope.beforeAddToCartHook(payload)

          $scope.afterAddToCartHook(payload)

          CPQPromotionsController

          $scope.beforeDeletePromotionItemHook(payload)

          scope.afterDeletePromotionItemHook(payload);

          CPQCartItemController

          $scope.beforeAddToCartHook(payload)

          $scope.afterAddToCartHook(payload);

          $scope.beforeDeleteItemFromCartHook(payload)

          $scope.afterDeleteItemFromCartHook(payload)

          Tip
          Tip

          Using this approach to override functions decreases maintenance and the risk of missing functionality in future releases. It also decreases maintenance needs.

          example
          example

          Sample Controller Override

          vlocity.cardframework.registerModule.controller('customOverrideController',
           ['$scope', 'CPQOverrideService', function($scope, CPQOverrideService) {
            #var overrideFunctions = {
             'beforeAddToCartHook': function(parent, obj) {
              alert('Hurray!');;
             }
            };
          
            CPQOverrideService.addToOverrideList('CPQCartItemController', overrideFunctions);
           }]);
          

          To override a controller:

          1. Create a new controller.
          2. Go to the Vlocity Template that contains the function to override.
          3. On the HTML Code tab, enter the appropriate markup to initialize the custom controller. For example:
            <div ng-controller="customOverrideController"></div>
          4. On the JavaScript Code tab, enter the appropriate code to register the custom controller and override the default function using CPQOverrideService.
           
          Loading
          Salesforce Help | Article