Sample code for ZQFClient helper methods
Code samples that demonstrate how to use ZQFClient helper methods to update charges, products, and discounts in CPQ hooks.
Sample code 1
Update charges based on rateplan name and charge name - This sample shows how to use updateCharges() in an afterProductAdd hook to apply different charge updates based on the rate plan name, such as setting discount and quantity values for specific plans like JIO and Airtel
import { LightningElement, api } from 'lwc';
import ZQFClient from 'zqu/zqfClient';
export default class HooksHandler extends LightningElement {
@api quoteState;
@api pageState;
get client() {
return ZQFClient.from(() => this.quoteState, {
pageState: () => this.pageState
});
}
@api
afterProductAdd() {
const qs = this.client;
const updateProductsEvent = qs.updateCharges([
{
filter: (charge, plan) => plan.record.Name === 'JIO',
update: {
zqu__Discount__c: 25,
zqu__Quantity__c: 12
}
},
{
filter: (charge, plan) => plan.record.Name === 'Airtel',
update: {
zqu__Discount__c: 15,
zqu__Quantity__c: 10
}
}
]);
this.dispatchEvent(updateProductsEvent);
return { proceed: true };
}
}
Sample code 2
Update Rateplans,Charges and Tiers - This sample shows how to use updateProducts() to update multiple record types in a single event, including charge discounts, tier discounts, and rate plan changes after a product is added.
import { LightningElement, api } from 'lwc';
import ZQFClient from 'zqu/zqfClient';
export default class HooksHandler extends LightningElement {
@api quoteState;
@api pageState;
@api
afterProductAdd() {
const qs = ZQFClient.from(() => this.quoteState, {
pageState: () => this.pageState
});
const updateProductsEvent = qs.updateProducts({
charges: [
{
filter: (charge) => charge.record.Name === 'Per MB Charge',
update: {
zqu__Discount__c: 22
}
}
],
tiers: [
{
filter: (tier, charge) =>
charge.record.Name === 'Recurring Charges -3Tier' &&
tier.record.zqu__StartingUnit__c === 0 && tier.record.zqu__EndingUnit__c === 50,
update: {
zqu__Discount__c: 5
}
},
{
filter: (tier, charge) =>
charge.record.Name === 'Recurring Charges -3Tier' &&
tier.record.zqu__StartingUnit__c === 51 && tier.record.zqu__EndingUnit__c === 100,
update: {
zqu__Discount__c: 10
}
}
],
ratePlans: [
]
});
this.dispatchEvent(updateProductsEvent);
return { proceed: true };
}
}Sample code 3
Update discount in a selected interval - This sample shows how to use updateChargesInInterval() to update a charge field for a specific ramp interval, such as setting the discount for the Per MB Charge only in the selected interval instead of across the full quote.
import { LightningElement, api } from 'lwc';
import ZQFClient from 'zqu/zqfClient';
export default class HooksHandler extends LightningElement {
@api quoteState;
@api pageState;
@api
afterProductAdd() {
const qs = ZQFClient.from(() => this.quoteState, {
pageState: () => this.pageState
});
const updateProductsEvent = qs.updateChargesInInterval(2, [
{
filter: (charge) =>
charge.record.Name === 'Per MB Charge',
update: {
zqu__Discount__c: 20
}
}
]);
this.dispatchEvent(updateProductsEvent);
return { proceed: true };
}
}interval index: 2
interval id: if your interval object has an id
interval start date: '2026-10-13'
full interval object: { index: 2, startDate: '2026-10-13', endDate: '2027-01-12' }