Notifications
Clear all
Oct 18, 2022 8:57 am
How to use javascript qcp (quote calculator plugin) to do roll ups on quote line items in salesforce cpq
2 Replies
Oct 18, 2022 9:00 am
Reference:
Custom Package Total Calculation | Salesforce CPQ Developer Guide | Salesforce Developers
Video 1: https://youtu.be/Hud_uvrYXe4 2: https://youtu.be/YfciF4kw_ZY
Check out this sample code:
// After calculate method to roll up List Price of childs to parent export function onAfterCalculate(QuoteModel, QuoteLineModel) { var objectKeys = {}; // variable to store keyvalue pair var key = ''; QuoteLineModel.forEach(function (line) { var prodType = line.record['PBProductType__c']; console.log("prodType", prodType); // if(prodType != null && ( prodType=='TPN' || prodType=='Service' || prodType=='AMC' || prodType== 'Software License' )){ if(prodType != null)){ var parent1 = line.parentItem; // getting parent record //check if parent record is not empty if(parent1 != null){ var Parent1key = parent1.record['SBQQ__Number__c'] + '$$' + parent1.record['PBProductType__c']; // creating key if (objectKeys[Parent1key] != null && objectKeys[Parent1key] != undefined) { objectKeys[Parent1key]['SBQQ__NetTotal__c'] = objectKeys[Parent1key]['SBQQ__NetTotal__c'] + line.record['SBQQ__NetTotal__c']; }else { // if objectkeys is empty assign this JSON (incase of 1st pass) var feeItems = { 'SBQQ__NetTotal__c': line.record['SBQQ__NetTotal__c'] }; objectKeys[Parent1key] = feeItems; } var parent2 = parent1.parentItem; if(parent2 != null ){ var Parent2key = parent2.record['SBQQ__Number__c'] + '$$' + parent2.record['PBProductType__c']; // creating key if (objectKeys[Parent2key] != null && objectKeys[Parent2key] != undefined) { objectKeys[Parent2key]['SBQQ__NetTotal__c'] = objectKeys[Parent2key]['SBQQ__NetTotal__c'] + line.record['SBQQ__NetTotal__c']; }else { // if objectkeys is empty assign this JSON (incase of 1st pass) var feeItems = { 'SBQQ__NetTotal__c': line.record['SBQQ__NetTotal__c'] }; objectKeys[Parent2key] = feeItems; } } var parent3 = parent2.parentItem; if(parent3 != null ){ var Parent3key = parent3.record['SBQQ__Number__c'] + '$$' + parent3.record['PBProductType__c']; // creating key if (objectKeys[Parent3key] != null && objectKeys[Parent3key] != undefined) { objectKeys[Parent3key]['SBQQ__NetTotal__c'] = objectKeys[Parent3key]['SBQQ__NetTotal__c'] + line.record['SBQQ__NetTotal__c']; }else { // if objectkeys is empty assign this JSON (incase of 1st pass) var feeItems = { 'SBQQ__NetTotal__c': line.record['SBQQ__NetTotal__c'] }; objectKeys[Parent3key] = feeItems; } } } } }); //for loop to assign calculated values to the fields QuoteLineModel.forEach(function (line){ var prodType = line.record['PBProductType__c']; if (prodType != null) { var seqNum = line.record['SBQQ__Number__c']; var key = seqNum + '$$' + prodType; //setting key for parent bundle if (objectKeys[key] != null && objectKeys[key] != undefined) { line.record['Rollup_Total__c'] = objectKeys[key]['SBQQ__NetTotal__c']; // assign the total value } } }); return Promise.resolve(); }
Jan 08, 2023 11:15 am
Or instead, you could simply use the CPQ special field Product Total or Product Option Total to resolve this.