BPM to add QuoteHedMsc

Probably you are missing the ‘Db.Validate();’

I tried adding this before and after the Update. I’ll paste my code below. As I mentioned, it creates the charge on cue but then when I refresh the quote, it disappears.

  if (QuoteAmt > 1000 && !ExistingCharge)
  {

    decimal Pct = 3;
    
    Erp.Contracts.QuoteSvcContract boQuote = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>(Db);
    Erp.Tablesets.QuoteTableset dsQuote = new Erp.Tablesets.QuoteTableset(); 
    
    dsQuote = boQuote.GetByID(QuoteNum);
  
    boQuote.GetNewQuoteHedMsc(ref dsQuote, QuoteNum, 0, 1);
   
    var NewMiscCharge = (from m in dsQuote.QuoteHedMsc
                         where m.RowMod == "A" && m.Company == callContextClient.CurrentCompany
                         select m).FirstOrDefault();
  
    if (NewMiscCharge != null)
    {    
      NewMiscCharge.SeqNum = NextSeqNum;    
      
      NewMiscCharge.MiscCode = "CCFE";  
      boQuote.GetMiscChrgDefaults(ref dsQuote, "QuoteHedMsc");
  

      var miscAmount = QuoteAmt * Pct;
      NewMiscCharge.CurrencySwitch = false;
      NewMiscCharge.Type = "P";
      NewMiscCharge.Percentage = Pct;
      boQuote.ChangeMiscPercent(ref dsQuote, "QuoteHedMsc");
      
      NewMiscCharge.FreqCode = "F";
      
 
      boQuote.Update(ref dsQuote);
      Db.Validate();
                                
      }

@dhewi - I read your comments on a similar post. Can you think of any reason the misc charge would get created in the quote but then disappear upon refreshing the quote?

One last nugget:
When i run a BAQ of the QuoteMsc table, there is a charge there. I noticed that the QtyNum is 1 for all of the entries I’ve made using the BPM. However, I have specifically set that field to be 0, since I see all the “real” entries have 0 for the QtyNum. Something is forcing my value to 1. Could this be related?

This is a BPM? And it appears when the BPM runs but then is visible in the data and not in the refreshed parent quote? Obviously something isn’t linking up correctly, and the QtyNum seems suspicious. If you use

boQuote.GetNewQuoteHedMsc(ref dsQuote, QuoteNum, 0,0);

does that make any difference?

@dhewi - It is a post-processing BPM on Quote.Update. I did change the line you mentioned. I then took it a step farther an explicitly tried to set the value to 0. But it keeps coming in to the QuoteMsc table as QtyNum = 1. I did a trace and I am firing all the methods that it does when I actually create a misc charge through the UI. I know I’m close…

You know what else is interesting. I have a check for an existing charge ahead of the code I pasted. See below.


  bool ExistingCharge = false;
  int SeqNum = 0;
  var MiscCharges = (from qh in Db.QuoteMsc
                      where qh.QuoteNum == QuoteNum
                      && qh.QuoteLine == 0
                      && qh.Company == callContextClient.CurrentCompany
                      select qh);
  
  if (MiscCharges.Any())
  {
    foreach (var EachCharge in MiscCharges)
    {
      SeqNum = EachCharge.SeqNum;
      if (EachCharge.MiscCode == "CCFE")
      {
        ExistingCharge = true;
        break;
      }
  
    }    
  }
  
  int NextSeqNum = SeqNum + 1;

This appears to work - but after I change the quantity on a line, the original charge shows back up but then disappears again after I refresh again. At no point is there a misc. charge on the Summary tab being added to the potential.

Do you have a dsHolder.Attach in your BPM? That wouldn’t affect it disappearing, but it might make a difference to whether it’s there before refreshing.

Not that I know of. I tried Pre-Processing and it does the same monkey business. I will try to use the method widgets next instead of custom code.

The only significant things I can see that are different to the code that works for me are:

SeqNum is always zero for a fresh row, and it gets set automatically on save.
DocDspMiscAmt / MiscAmt / DocMiscAmt all needed setting, but the ChangeMiscPercent might deal with that.

If you’ve used a BO to update, you don’t need Db.Validate.

Great points. I’ll check when I get back from lunch. I know I was manually setting SeqNum. I could totally see that throwing a wrench in the gears.

I have tweaked everything but I keep getting the same result. The charge shows up there temporarily, but then deletes itself when I refresh the Quote. The charge does show up when i do a BAQ of the QuoteMsc table but as we discussed, the QtyNum is 1 no matter what I try. And it certainly seems like this is not what we want.

@hkeric.wci - you had good feedback on the Order side. Any ideas on this? I get the Misc Charge to populate on the QuoteHed but it doesn’t stay there. I hit refresh and it disappears. A BAQ of the QuoteMsc table reveals that the charge is there but it has a 1 in the QtyNum field - even though I am trying to get it to enter with a 0 (just like it would if I entered the charge through the UI). We were thinking that might be causing some glitch in the matrix because the quote doesn’t want to recognize that as a valid charge. Any ideas?

Dan.

Understand this one may be a bit stale - but I seem to remember running into the exact same thing and did a workaround by update the record after creation to zero qtynum. I.E.

svc.GetNewQuoteMsc(ref ds,ttQuoteDtl_Row.QuoteNum, ttQuoteDtl_Row.QuoteLine,0);

var QuoteMscNew = (from row in ds.QuoteMsc where row.QuoteNum == quotenum && row.QuoteLine == ttQuoteDtl_Row.QuoteLine && row.MiscCode != “FRGT” select row).FirstOrDefault();

 QuoteMscNew.QtyNum            = 0;
 QuoteMscNew.MiscCode          = strMiscCode; 
 QuoteMscNew.Description       = " Tariff - Line "+ttQuoteDtl_Row.QuoteLine.ToString();
 QuoteMscNew.MiscAmt           = ttQuoteDtl_Row.TariffAmt_c;   
 QuoteMscNew.DocMiscAmt        = ttQuoteDtl_Row.TariffAmt_c;   
 QuoteMscNew.FreqCode          = strFreqCode;
    try
            {               
               svc.Update(ref ds); // hold any returned errors 
            }
            catch (Exception e)
            {
                msg = msg + System.Environment.NewLine + "Update Exception " + e.Message;
            }