If you’re here you’re eagerly trying to figure out how to update Quote Line Group values in a price rule. Unfortunately, you can’t. Yet. But you can in a QCP! Here’s a basic sample that copies the Quote Account value into the Quote Line Group Account field.
QCP Rules
- Methods have to be “export function …”. You can’t just declare a function and expect it to work properly.
- You must implement one of the expected functions (onInit, onBeforeCalculate, onBeforePriceRules, onAfterPriceRules, onAfterCalculate, isFieldVisible, isFieldEditable).
- You must keep your “fields” fields on the Custom Script record up to date with the fields you’re referencing/updating within the QCP. If you’re touching line fields, add those fields to the Quote Line Fields field. If you’re touching group fields, add those fields to the Quote Line Group Fields field.
Expected Function Headers
// ---------------------------------------------------------
// these functions expect a Promise.resolve(); at the end.
// ---------------------------------------------------------
export function onInit(lines) { Promise.resolve(); }
export function onBeforeCalculate(quote, lines) { Promise.resolve(); }
export function onBeforePriceRules(quote, lines) { Promise.resolve(); }
export function onAfterPriceRules(quote, lines) { Promise.resolve(); }
export function onAfterCalculate(quote, lines) { Promise.resolve(); }
// ---------------------------------------------------------
// these functions expect a boolean at the end.
// ---------------------------------------------------------
export function isFieldVisible(fieldName, lineRecord) { return true; }
export function isFieldEditable(fieldName, lineRecord) { return true; }
Example After Calculate Function
//QuoteCalculatorJS
export function onAfterCalculate(quote, lines) {
if (quote.groups && quote.groups.length > 0) {
quote.groups.forEach(function(group) {
if (group.record != null) {
group.record['SBQQ__Account__c'] = quote.record['SBQQ__Account__c'];
var groupListTotal = 0;
// if there are lines,
if (lines && lines.length > 0) {
// loop through lines.
lines.forEach(function(line) {
// if this line's group id equals this group's id,
if (group.record['Id'] == line.record['SBQQ__Group__c']) {
groupListTotal += line.record['SBQQ__ListPrice__c'];
}
});
}
group.record['ListTotal__c'] = groupListTotal;
}
});
}
return Promise.resolve();
}
Hi,
I need to update the guote line group fields header values based on quote line in that particular group.
for example: i have to update one time total field on the group header.if the charge type of the Quote line is one time the it should sum up the quoteline and update it.
Hi Manusha! Yes you can do this! You would need to loop through your groups, then inside that loop, loop through your lines to gather line values and do some if statement testing of data for your specific criteria. If the criteria hits, set the values in the group!
Hey Dennis – we’re currently trying to write QCP to achieve exactly this. It seems others have tried but there doesn’t seem to be any examples of working code. I found this on stack exchange, but this user is also having a problem for the value to work. https://salesforce.stackexchange.com/questions/399549/qcp-to-summarize-quote-line-groups.
Is there another article we can reference?
I will add that we have replicated this in our sandbox using flow, which seems to be working. However, I have concerns about running flow against quote line group creation, resource allocation, DML limits, etc. Any help is appreciated.
Hey Drew! I’ll update this article with more detail and more code to show the update of values. Keep in mind, any values you’re using/updating need to be in the quote line group fields field on the custom script record. Also, I’m available for consulting services to help out on these types of things in the event you’re in need.
Updated the article! Let me know if I can be of any further help!
Thanks for the reply Dennis. Between my question and your response, we actually got it to work…except one small problem.
It seems to be with the timing of group creation. When a group is first created, and then lines are added, and the user hits Save (not calculate or quick save), QCP does not fire. After going back into edit lines, and then hitting quick save or calculate, it works as intended. And no issues with subsequent groups.
We’re using if(quote.record[‘SBQQ__LineItemsGrouped__c’]) as the initial condition, other than that variable definition is similar. Wondering if it also just the nature of onAfterCalculate, but would think hitting save would first save the groups to the database, then pricing waterfall would follow. Really appreciate the responses!
It might have something to do with your initial condition. The groups should come in as a variable on the quote js variable so you shouldn’t need to check if that field is set. Merely checking the groups on the quote variable should be enough. Happy to hop on a call to help debug if necessary. 👍🏻
I’ve also put an answer into that stackexchange question you linked. 👍🏻 🙂
Hi D P,
Great stuff.Keep rocking.
Do you know if QCP gets triggered when a value is updated from a trigger/process ?
I need to vet this out but I do believe it does.
Hi
I have a scenario where i have multiple QLG on a Quote and I would need a way to add product A to all QLG at once. how can we achieve this ?
This would need to be a custom solution using apex.
Hello. Do you have sample code of how to sum Quote Line totals to the Quote Line Group? It is needed and we have been using DLRS to calculate however it doesn’t work the first time b/c of the order of operations.
SCENARIO: I have multiple lines under a quote line group and need to sum the One Time Fees and Revenue as separate items. Each group could have different lines and amounts so the group should only sum the quote line items underneath it.
Yes you can definitely do this but I don’t have sample code. I’ve done this sort of thing before. This might have to be a next article!
Hello, I have a similar requirement. I have Admin Fee product in each quote line group. I have to calculate admin fee price based on % of net totals of other quote lines in that quote line group. I have written the logic in QCP. But it needs ‘Quick Save’ and then have click ‘Calculate’ to get correct pricing.
is there anything that i am missing? Or should this be done on apex trigger as Quote line group lookup on quote line is available later in the calculation stage?