Loading
Salesforce now sends email only from verified domains. Read More
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
          Declarative Calculation Procedures (Managed Package)

          Declarative Calculation Procedures (Managed Package)

          For the managed package runtime, declarative calculation procedures are a key component of the ratings engine. Along with calculation matrices, calculation procedures are the key components of any or ratings engine. Calculation procedures take an input JSON and run through a series of matrix lookups (calling values from calculation matrices) and calculations to calculate ratings for policy products.

          Managed Package app icon This information is for Omnistudio for Managed Packages. For Omnistudio on standard runtime, see Omnistudio Help.

          An OmniScript, Integration Procedure, or other component calls the Calculation Procedure and passes in JSON data. The Calculation Procedure calls Calculation Matrices and performs calculations in its steps. When it completes, the Calculation Procedure returns JSON data to the calling component.

          Calculation procedures can calculate coverage premiums, insured party premiums, insured item premiums, and insurance policy premiums. Calculation procedures can calculate attribute-based prices for products.

          Note
          Note

          Beginning with the Summer '19 release, declarative calculation procedures support:

          • Grouped calculation matrices

          • Row-versioned calculation matrices

          What's in a Calculation Procedure

          A well-formed calculation procedure contains the following elements:

          • Constants

            All the constants you need for each calculation step

          • Variables

            Input variables, all the variables you need for each calculation step and the group key and subgroup key if you're calling a group of matrices all the variables in calculation matrices you call in matrix lookup steps

          • Calculation steps, including:

            • Calculations

              Each calculation required to get to the correct result of the whole calculation procedure

            • Matrix lookups

              Finds one or more variable values in calculation matrices, based on one or more variable inputs

          • Aggregation steps (optional)

            If this calculation procedure will handle an array of inputs, aggregation steps will perform calculations over the output sets.

          How Calculation Procedures Work in Context

          Omniscripts, Integration Procedures, and other Vlocity processes can call a calculation procedure. The calculation procedure takes a JSON that gives the calculation procedure the ingredients it needs to complete its calculation.

          An OmniScript, Integration Procedure, or other component calls the Calculation Procedure and passes in JSON data. A preprocessor Apex class runs before the Calculation Procedure steps start. The Calculation Procedure calls Calculation Matrices and performs calculations in its steps. After the steps, a postprocessor Apex class runs. Then the Calculation Procedure returns JSON data to the calling component.

          Calculation procedures can take a single input, a single set of inputs, or multiple arrays of inputs.

          Here's an example of a single set of input values, as passed in by a JSON:

          {
             "input": {
                "opMVRPoints": "0",
                "opAccidentPoints": "0",
                "driverGoodStudent": "N",
                "driverMaritalStatus": "M",
                "driverGender": "M",
                "driverYrsExp": "14",
                "driverMileage": "7500",
                "driverUse": "Business"
             }
          }

          The calculation procedure runs through all its steps once for a single input or single array of inputs. It returns a calculation or array of calculations. The output JSON for the calculation procedure that processed this input is:

          {
             "output": [
                {
                   "calculationResults": [
                      {
                         "driverCCD": 1.11,
                         "driverCOLL": 0.92,
                         "driverMED": 0.91,
                         "driverUM": 0.92,
                         "driverBIPD": 0.86,
                         "autoSafeDriver__driverSafe": "Y",
                         "ID": "input"
                      }
                   ],
                   "aggregationResults": {}
                }
             ]
          }

          Because the calculation procedure did not have any aggregation steps, there are no aggregation results in the output JSON.

          How Aggregation Works in Calculation Procedures

          When you add aggregation steps to your calculation procedure, the calculation procedure puts together the results of each run through itself, performs operations on them, then outputs the results of the operations. Here's what that looks like:

          An OmniScript, Integration Procedure, or other component calls the Calculation Procedure and passes in multiple sets of JSON data. The Calculation Procedure runs once for each set of inputs, calling Calculation Matrices and performing calculations in its steps in each run. All the runs are aggregated, then the Calculation Procedure returns JSON data to the calling component.

          For example, in a simple case, the calculation procedure needs to calculate a group premium based on a census. Each census member has a set of input values that's passed to the calculation procedure. The calculation procedure runs all of its calculation steps for each member, resulting in an output (premium) for each member. So now it's got an array of outputs. To sum the premiums of all the members of the census, an aggregation step sums all the premium output variables.

          Note
          Note

          The aggByKey functionality in the following example is available in Vlocity Insuranceand Vlocity Health only.

          In a more complex scenario, an auto insurance calculation procedure must calculate a premium per instance of car and driver. For example, a user needs to rate out a policy for two cars—a Toyota Prius and a Tesla Model S. The Prius is driven by Roger and Amy, and the Model S is driven by Amy and Steve. The calculation procedure needs to calculate and aggregate results separately for the Prius and for the Model S.

          In this case:

          • instanceKey = car+driver

          • aggByKey = carModel

          To complete this calculation with aggregation, the calculation procedure uses aggByKeys. When the calculation procedure receives aggByKeys as an input, it runs through the aggregation steps once per aggByKey. Here's what that looks like:

          An OmniScript, Integration Procedure, or other component calls the Calculation Procedure and passes in multiple sets of JSON data. The Calculation Procedure runs once for each set of inputs, calling Calculation Matrices and performing calculations in its steps in each run. All the runs are aggregated, but the aggregation has subgroups based on aggByKey values. Then the Calculation Procedure returns JSON data to the calling component.

          So for the example above, the calculation procedure groups the results of its four calculation step runs into two subsets: one for the instances for the Prius and another for the instances for the Model S. Then it runs the aggregation steps twice: once for the Prius and again for the Model S. The calculation procedure returns two aggregation results—one for each vehicle.

          You don't need to add aggByKeys and instanceKeys to your calculation procedure as variables. As long as the aggByKey option and includeInputKeys option are set correctly in the services, the getRatedProduct and repriceProduct services will pass the keys in automatically as part of the input JSON.

          Preprocessor and Postprocessor Classes

          These are Apex classes that you can use if you have to massage your input data or output data before and after it's processed by a calculation procedure. See Preprocessor Class Example (Managed Package).

          If you think you need to use preprocessor classes or postprocessor classes, please contact your Vlocity representative to verify that your use case requires that you write these classes. (We have a lot of tools that are easier and more configurable now, and some of those might work better for you.)

           
          Loading
          Salesforce Help | Article