top of page

Apply amount discount to a group

Introducing

here's a step-by-step tutorial on how to apply a discount on a specific quoteline group in Salesforce CPQ:

Step 1

Create a custom field and add it to the field set of the Line Editor

· Navigate to Setup in your Salesforce org

· Click on Object Manager and select the Quote Line object

· Create a custom field of type Number (e.g., "Additional Discount Rate")

· Add this custom field to the Line Editor field set, which will make it visible on the Quote Line Editor page


Step 2

Create a custom script to apply the discount

· Navigate to the Salesforce CPQ app

· Click on the “Custom Scripts” tab

· Click on "New" to create a new custom script

· Give your script a name paste the following code into the script editor:




export function onAfterCalculate(quoteModel, quoteLines) {
quoteModel.groups.forEach(function(group){
console.log('---name'+ group.record.Name);
if(group.record.Name === "Groupe1" && quoteModel.record.Montantremise!=0){
group.record["SBQQ__AdditionalDiscountRate__c"] = (quoteModel.record.MontantRemise__c/group.record.SBQQ__ListTotal__c)*100;
console.log('---SBQQ__AdditionalDiscountRate__c:'+ group.record.SBQQ__AdditionalDiscountRate__c);
}
});

return Promise.resolve();
}

This code applies a discount to a group with the name "Groupe1" if field ("Montantremise") in the Quote record is not equal to zero.

The discount rate is calculated based on the custom field "SBQQ__ListTotal__c" of the group and the custom field " MontantRemise__c" of the Quote record.

Step 3: Save and activate the custom script .

That's it! Now, when you create or edit a Quote in Salesforce CPQ, the custom script will automatically apply a discount to any quoteline group with the name "Groupe1" if the conditions are met. The discount rate will be calculated based on the values in the Quote and Quote Line records, and displayed in the custom field you created.


Result


3 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page