Quote Calculator Plugin Methods

The Quote Calculator Plugin can reference these seven methods. You can export any, all, or none of them to achieve your desired behavior.

Required Editions
Available in: Salesforce CPQ Winter ’16 and later

API Version Management 

In general, Salesforce CPQ uses Salesforce API that’s one version behind the newest Salesforce API. For example, Salesforce Summer ‘21 uses Salesforce API version 52.0, so Salesforce CPQ Summer ‘21 uses Salesforce API version 51.0.

If you need to reference entities or fields Salesforce API version that’s newer than what you’re using in Salesforce CPQ, use the JSforce property assignment conn.version='x';, replacing x with the version that you want to use. For example, the following method shows how to overwrite the default API version to version 52.0.

1export function onInit(quote, conn) {
2   conn.version = '52.0';
3   return conn.query("SELECT Name FROM ConsumptionSchedule")
4      .then(function (results) {
5         console.log(results);
6         return Promise.resolve();
7      })
8}

onInit 

ParamTypeDescription
{QuoteLineModel[]}quoteLineModelsAn array containing Javascript representations of all lines in a quote.

The calculator calls this method before formula fields are evaluated. Returns {promise}.

1export function onInit(quoteLineModels) {
2return Promise.resolve();
3};

onBeforeCalculate 

ParamTypeDescription
{QuoteModel}quoteModelJavascript representation of the quote you’re evaluating
(QuoteLineModel[]}quoteLineModelsAn array containing Javascript representations of all lines in the quote

The calculator calls this method before calculation begins, but after formula fields have been evaluated. Returns {promise}.

1export function onBeforeCalculate(quoteModel, quoteLineModels) {
2return Promise.resolve();
3};

onBeforePriceRules 

ParamTypeDescription
{QuoteModel}quoteModelJavascript representation of the quote you’re evaluating
(QuoteLineModel[]}quoteLineModelsAn array containing Javascript representations of all lines in the quote

The calculator calls this method before it evaluates price rules. Returns {promise}.

1export function onBeforePriceRules(quoteModel, quoteLineModels) {
2return Promise.resolve();
3};

onAfterPriceRules 

ParamTypeDescription
{QuoteModel}quoteModelJavascript representation of the quote you’re evaluating
(QuoteLineModel[]}quoteLineModelsAn array containing Javascript representations of all lines in the quote

The calculator calls this method after it evaluates price rules. Returns {promise}.

1export function onAfterPriceRules(quoteModel, quoteLineModels) {
2return Promise.resolve();
3};

onAfterCalculate 

ParamTypeDescription
{QuoteModel}quoteModelJavascript representation of the quote you’re evaluating
(QuoteLineModel[]}quoteLineModelsAn array containing Javascript representations of all lines in the quote

The calculator calls this method after it completes a calculation, but before re-evaluating formula fields. Returns {promise}

1export function onAfterCalculate(quoteModel, quoteLineModels) {
2return Promise.resolve();
3};

isFieldVisible 

This method can’t be used to alter data.

Note

ParamTypeDescription
{FieldName}StringName of the field that will be hidden or made visible
(QuoteLineModelRecord}quoteLineModelRecordJavascript representation of the SObject record of line you’re evaluating

The calculator calls this method after it completes a calculation. Returns {Boolean}

1export function isFieldVisible(fieldName, quoteLineModelRecord) { 
2    
3    if (fieldName == 'SBQQ__Description__c') { 
4    return false; 
5    } 
6    
7    return true; 
8    
9    };

isFieldEditable 

This method can’t be used to alter data.

Note

ParamTypeDescription
{FieldName}StringName of the field that will be made read-only or editable
(QuoteLineModelRecord}quoteLineModelRecordJavascript representation of the SObject record of line you’re evaluating

The calculator calls this method after it completes a calculation. Returns {Boolean}

1export function isFieldEditable(fieldName, quoteLineModelRecord) { 
2    
3    if (fieldName == 'SBQQ__Description__c') { 
4    return false; 
5    } 
6    
7    return true; 
8    
9    };