rolling up values o...
 
Notifications
Clear all

rolling up values on quote line editor in salesforce cpq

3 Posts
1 Users
0 Likes
84 Views
Posts: 205
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

How to use javascript qcp (quote calculator plugin) to do roll ups on quote line items in salesforce cpq

2 Replies
Posts: 205
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

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();
}
Reply
Posts: 205
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

Or instead, you could simply use the CPQ special field Product Total or Product Option Total to resolve this. 

Reply
Share: