I'm writing a custom script for CPQ Calculator. I'm using the onAfterCalculate
method to insert new quote lines using JSForce.
export function onAfterCalculate(quote, lines, conn) {
let supportProducts = [];
// logic to add support products based on existing products in the quote
// if an existing line item needs a support product and then is no line
// item with that product in 'lines' array, then add a new line to 'supportProducts'
// array
if (supportProducts.length > 0) {
conn.sobject('SBQQ__QuoteLine__c').create(supportProducts, function(err,ret){
console.log(err, ret);
});
} else {
console.log('nothing to insert');
}
}
I'm facing a few issues with this approach.
When I delete the support line, the 'lines' array doesn't contain that item and my logic inserts a new line item for the same support product.
I want to know what's the best practice around inserting new quote lines in CPQ. Should it be done via custom script or is there any existing variable that's passed in the onAfterCalculate
method which we can use to append the line item and it will automatically insert the line.
How to prevent re-insertion of support product when the same support product is being deleted from the Line Editor?