1

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?

1
  • Have you tried using product rules instead to add or remove lines? May 5, 2021 at 22:00

1 Answer 1

1

I have tried extensively to support this use-case and have talked with the CPQ product team at Salesforce, and this is an unsupported use-case.

I have seen one implementation of CPQ use a trigger to insert a quote line which actually did work and it showed up in the Quote Line Editor after Save/QuickSave.

Generally I would try to avoid these types of use-cases as CPQ was not designed to work this way, so it ends up being problematic with other parts of CPQ.

The best outcome would be if you can figure out a way to use the configurator to add new products.

Also, I have not used this and have seen it done once, but there is the option to add a custom configurator that could potentially be of value to you depending on your use-case: https://developer.salesforce.com/docs/atlas.en-us.cpq_dev_plugins.meta/cpq_dev_plugins/cpq_external_config.htm

There are some (not very good) examples on GitHub you can look at: https://github.com/search?q=cpq+easyXDM&type=code

1
  • Yes, that's what I figured. I ended up inserting lookup query records from QCP and then using product rules with lookup queries which is working fine now.
    – jagmohan
    Jul 29, 2021 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.