Since there is no way to use summary variables or roll up summary fields or price rules on quote line groups, I was wondering if there is to way to write a custom QCP that calculates the NetTotal for each quote line group with a specific condition. That condition would be only the quote line items in the group where subscription type = "One-time".
- For each quote line group, loop through each quoteline and sum the net total to store in a variable
- Update custom quote line group field with that variable value.
Update here is below code I have in a custom script record...however it does not seem to update my Quote Line Group field. I don't receive any errors.
function calculateOneTimeProductsTotal(quotelineGroup) {
var oneTimeProductsTotal = 0;
quotelineGroup.getQuotelineItems().forEach(function(quotelineItem) {
var product = quotelineItem.getProduct();
var subscriptionType = product.get("Subscription_Type__c");
if (subscriptionType === "One-time") {
oneTimeProductsTotal += quotelineItem.get("SBQQ__NetTotal__c");
}
});
quotelineGroup.set("One_Time_Services_Total__c", oneTimeProductsTotal);
}
function calculate() {
var quoteModel = window.quoting.model;
var quotelineGroups = quoteModel.getQuotelineGroups();
quotelineGroups.forEach(function(quotelineGroup) {
calculateOneTimeProductsTotal(quotelineGroup);
quotelineGroup.on("change:quotelineitems", function() {
calculateOneTimeProductsTotal(quotelineGroup);
});
});
}