Loading

Configure a CPQ Product to be priced in real time

Publiceringsdatum: Sep 27, 2025
Beskrivning
By default, new Price Rule changes only take effect when entering and leaving the Quote Line Editor.

This scenario covers the use of a custom Object containing a list of pricing data that is uploaded regularly.  In this use case, real-time updates might occur while Sales Users are editing a Quote in the Quote Line Editor and the new data would want to be captured on each 'Calculate' event. 
Lösning

A Quote Calculator Plugin (QCP) is needed in order to accomplish this use case. Using JSForce, a query can pull the correct pricing data when called.

A basic example of how to set up the pricing can be found below, where QCP_Lookup_Table__c is the Object from which the pricing is queried, and fields Partner_Discount__c (Percent) and ProductId__c (text) are on the QCP Lookup Table object. The Custom Script record's Code field contains the following text and sets the Quote Line's Partner Discount field based on Quote Line matching the Product Id field on the Lookup Table.
 

export function onBeforeCalculate(quote, lines, conn){
  if(lines.length > 0){
    var productIds = [];
    lines.forEach(function(line) {
      if(line.record['SBQQ__Product__c']){
        productIds.push(line.record['SBQQ__Product__c']);
      }
    });
    if (productIds.length){
      var productIdList = "('" + productIds.join("', '") + "')";
      var queryString = 'SELECT Id, Partner_Discount__c, ProductId__c FROM QCP_Lookup_Table__c WHERE ProductId__c IN ';
      queryString += productIdList;
      return conn.query(queryString)
      .then(function(results){
        if (results.totalSize){
          var discByProduct = {};
          results.records.forEach(function(record){
            discByProduct[record.ProductId__c] = record.Partner_Discount__c;
            
          });
          lines.forEach(function(line){
            if(line.record['SBQQ__Product__c']){
              line.record['SBQQ__PartnerDiscount__c'] = discByProduct[line.record['SBQQ__Product__c']] || '';    
            }
          });
        }
        });  
    }
  }
return Promise.resolve();
} 
Ytterligare resurser
SEE ALSO
Knowledge-artikelnummer

000380849

 
Laddar
Salesforce Help | Article