First, we need to create a bundle product
Login with CPQ developer org and then,
Go to the App launcher à Salesforce CPQ app à select Products à New
1.Product Name à Basic Unlimited InternetUp to 40Mbps & Product code à Basic Unlimited InternetUp to 40Mbps & Active à True
2. Configuration type à Allowed & Option layout à Sections & Configuration event à Always & Option Selection method à Click
3. Subscription Pricing à Fixed price & Subscription Term à 12 & Subscription Type à Renewable and Save
Now, we need to add the Price book for the Product
Select Basic Unlimited InternetUp to 40Mbps à Related list à Price Bookà Add to Price Book & List Price à 499 &
Active à True and Save
Now, we need to add the Unlimited Internet Installation product in the Basic Unlimited InternetUp to 40Mbps product option
Select Basic Unlimited InternetUp to 40Mbps product à Related list à Option à Add Unlimited Internet Installation and Save
So, need to create the Custom Script for the calculation
Go to App launcher à Custom Script à New
Script Name à Bundle Script and Product code given below code
export function onInit(quoteLineModels, conn) {
console.log('onInit()', quoteLineModels, conn);
printRecords(quoteLineModels);
return Promise.resolve();
}
export function onBeforeCalculate(quoteModel, quoteLineModels, conn) {
console.log('onBeforeCalculate()', quoteModel, quoteLineModels, conn);
printRecords(quoteLineModels);
printRecords(quoteLineModels);
return Promise.resolve();
}
export function onBeforePriceRules(quoteModel, quoteLineModels, conn) {
console.log('onBeforePriceRules()', quoteModel, quoteLineModels, conn);
printRecords(quoteLineModels);
printRecords(quoteLineModels);
return Promise.resolve();
}
export function onAfterPriceRules(quoteModel, quoteLineModels, conn) {
console.log('onAfterPriceRules()', quoteModel, quoteLineModels, conn);
printRecords(quoteLineModels);
quoteLineModels = Array.isArray(quoteLineModels) ? quoteLineModels : [quoteLineModels];
var quoteLineModelObj = quoteLineModels.map(quoteLineModels => quoteLineModels.record);
console.log('quotelineModels' + quoteLineModels.map(quoteLineModelObj => quoteLineModels.record));
quoteLineModelObj.forEach(line => {
console.log('line.Name', line.Name);
})
return Promise.resolve();
}
export function onAfterCalculate(quoteModel, quoteLineModels, conn) {
console.log('onAfterCalculate()', quoteModel, quoteLineModels, conn);
if (quoteLineModels != null) {
quoteLineModels.forEach(function (line) {
if (line.record["SBQQ__OptionLevel__c"] == null ){
line.record["SBQQ__Quantity__c"] = 0;
}
});
}
if (quoteLineModels != null) {
quoteLineModels.forEach(function (line) {
var parent = line.parentItem;
console.log(parent);
if (parent != null && parent.record["SBQQ__OptionLevel__c"] == null ){
var parentQuantity = parent.record["SBQQ__Quantity__c"] || 0;
var optionLevel = line.record["SBQQ__OptionLevel__c"];
var productCode = line.record["SBQQ__ProductCode__c"];
var qty = line.record["SBQQ__Quantity__c"];
var calculatedQty = getQuantity(optionLevel, productCode, qty);
parentQuantity += calculatedQty;
parent.record["SBQQ__Quantity__c"] = parentQuantity;
}
});
}
printRecords(quoteLineModels);
printRecords(quoteLineModels);
return Promise.resolve();
}
export function printRecords(obj) {
obj = Array.isArray(obj) ? obj : [obj];
console.log(obj.map(obj => obj.record));
}
function getQuantity(optionLevel, productCode, qty) {
var quantity = 0;
if (productCode == "Unlimited Internet Installation") {
quantity = qty;
}
return quantity;
}
And Quote line fields give these value
SBQQ__Quantity__c
SBQQ__OptionLevel__c
SBQQ__ProductCode__c and save
Now, add this custom script in the CPQ plugin
Go to Setup à Installed package à Salesforce CPQ à Configure à Plugins à Quote Calculator Plugin à Bundle Script and Save
Now go to the Quotes à Select any quote à Edit lines à Add products à Select Basic Unlimited InternetUp to 40Mbps à select à give the quantity as 6 for Unlimited Internet Installation à Select
And see the results below for the quantity of Basic Unlimited InternetUp to 40Mbps product quantity also getting 6