Happy Business Starts Here

Not able to add the Discount % value to the Discount Percentage charge using zQuoteUtil methods

Highlighted
Zuora Support

Not able to add the Discount % value to the Discount Percentage charge using zQuoteUtil methods

Problem: Customer was facing an issue when updating the Discount % value on the Discount Percentage charge using the zQuoteUtil methods. When using the Code below they were getting the error as shown in the Error section after the code. 

 

Id quoteId = 'Please insert the Quote ID here';
List<Id> prpIds = new List<Id>();
prpIds.add('Please insert the PRP ID here');
// Get charge groups ready to be added
List<zqu.ZChargeGroup> zcgs  = zqu.ZQuoteUtil.getChargeGroups(quoteId, prpIds);
for (zqu.zChargeGroup zcg : zcgs){
    for(zqu.zCharge zc : zcg.zCharges){
      System.debug('charge is :' + zc);
      if(zc.MODEL == 'Discount-Percentage'){
        zc.DISCOUNT = '50';
        zqu.zQuoteUtil.calculateChargesOnDiscountChange(zcg.zCharges);
      }
   }
}
zqu.ZQuoteUtil.addChargeGroups(zcgs );

 

Error: 

Validation errors were found on the charge groups: The charge group Fixed Discount Product (Fixed Discount) with Type 1 on Quote <Id> does not support updating. 

inline1961095750.png

 

Solution: On researching this more we found that the "Value" of charges is actually stored in EFFECTIVE_PRICE, even in discount charges. And hence on trying the below code we were able to successfully update the value of the Discount % and also update the Quote Metrics value on the Quote at the same time. 

zqu__Quote__c quote = [SELECT Id, zqu__Is_Charge_Expired__c FROM zqu__Quote__c WHERE Id = 'a275E000001JWvdQAG'];
Id quoteId = 'Please insert the Quote ID here';
List<Id> prpIds = new List<Id>();
prpIds.add('Please insert the PRP ID here');
// Get charge groups ready to be added
List<zqu.ZChargeGroup> zcgs  = zqu.ZQuoteUtil.getChargeGroups(quoteId, prpIds);
for (zqu.zChargeGroup zcg : zcgs){
    {
    for(zqu.zCharge zc : zcg.zCharges){
        System.debug('charge is :' + zc);
        if(zc.MODEL == 'Discount-Percentage'){
        zc.EFFECTIVE_PRICE = '50';
        zqu.zQuoteUtil.calculateChargesOnEffectivePriceChange(zcg.zCharges);
        }
    }
  }
zqu.ZQuoteUtil.addChargeGroups(zcgs);

quote.zqu__Is_Charge_Expired__c = true;
update quote;
}


Please find below the snapshot of the Product Selector page after running the code. 

inline-762604379.png






If you found my answer helpful, please give me a kudo ↑
Help others find answers faster by accepting my post as a solution √