I want to update the exchange rate on a quote in 2 ways,
Update the exchange rate of the current quote -
We have this working with custom code inside a pre-procesing method directive on Erp.Quote.Update. The custom code updates QuoteHed.ExchangeRate and all detail lines get updated with the new exchange rate.
Update the exchange rate when creating a duplicate quote -
This is the one we can’t get working properly. We set callContextBpmData.Character01 to a value in a pre-processing method directive on Erp.Quote.DuplicateQuote. We then run a QuoteHed In-Transaction Data Directive when callContextBpmData.Character01 is set, executing the same code for changing the exchange rate as in scenario 1. In this case, only OrderHed.ExchangeRate is changed and no recalculation of the detail line occurs.
Any ideas on how to get Scenario 2 working? Should we be using a different event?
I don’t know if this will work or not, but could you call an update BO on the post processing after duplicate? or call the the update BO on cleverly conditioned data directive on the quote head table? I think that if you call the BO from a BPM, the other BPM’s in place will still fire, so your scenario 1 BPM can do the work for scenario 2.
If you use the wizard to make an event on field change, you can call oTrans.Update() and it will save the form. Hopefully triggering your original BPM.
But after reading your scenario a little more closely, and seeing that you are using all BPM’s.
Can you see in your trace of scenario 1 any other calls besides update? I would have to play around with some stuff, but there is probably some onchange call that is being called in the update, and/or the duplicate quote doesn’t have the fields in the data set to do the changes.
This is where I am at with Scenario 2.
Method Directive Erp.Quote.DuplicateQuote -Post Processing
Custom Code
using(var quoteSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>(Db))
{
var ds = this.result;
int ct=0;
foreach(var dtl in ds.QuoteDtl)
{
dtl.SellingExpectedQty = (from qdd in Db.QuoteDtl where qdd.Company == dtl.Company && qdd.QuoteNum == sourceQuote select qdd).ToArray()[ct].SellingExpectedQty;
dtl.RowMod="U";
quoteSvc.ChangeSellingExpQty(ref ds);
ct++;
}
quoteSvc.Update(ref ds);
this.resultHolder.Attach(ds);
}
Data Directive on QuoteHed - InTransaction
Custom Code runs when callContextBpmData.Character01 = “UPDER”
foreach(var x in ttQuoteHed.Where(r=> r.Added() || r.Updated()))
{
var baseCurRate = (from c in Db.Currency where c.Company == x.Company && c.BaseCurr select c.CurrencyCode).FirstOrDefault();
callContextBpmData.Character02 = "Base:" + baseCurRate+ " Target: " + x.CurrencyCode + "RateType:" + x.RateGrpCode;
var currExtRate = (from ce in Db.CurrExRate where ce.Company == x.Company
&& ce.SourceCurrCode == x.CurrencyCode
&& ce.TargetCurrCode == baseCurRate
&& ce.RateGrpCode == x.RateGrpCode select ce).OrderByDescending(r=>r.EffectiveDate).FirstOrDefault();
if(currExtRate!=null)
{
callContextBpmData.Character02 += "___" + x.ExchangeRate.ToString();
x.ExchangeRate = currExtRate.CurrentRate;
}
}
The ExpectedQty updates correctly on the detail lines and the Exchange Rate updates on the header. The exchange rate does not recalculate the unit price on the detail lines like it does when changing the exchange rate on the form.
I moved the code from the Data Directive to the above method directive. Same result, the detail lines do not get recalculated.
using(var quoteSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>(Db))
{
var ds = this.result;
foreach(var x in ds.QuoteHed.Where(r=> r.Added() || r.Updated()))
{
var baseCurRate = (from c in Db.Currency where c.Company == x.Company && c.BaseCurr select c.CurrencyCode).FirstOrDefault();
callContextBpmData.Character02 = "Base:" + baseCurRate+ " Target: " + x.CurrencyCode + "RateType:" + x.RateGrpCode;
var currExtRate = (from ce in Db.CurrExRate where ce.Company == x.Company
&& ce.SourceCurrCode == x.CurrencyCode
&& ce.TargetCurrCode == baseCurRate
&& ce.RateGrpCode == x.RateGrpCode select ce).OrderByDescending(r=>r.EffectiveDate).FirstOrDefault();
if(currExtRate!=null)
{
callContextBpmData.Character02 += "___" + x.ExchangeRate.ToString();
x.ExchangeRate = currExtRate.CurrentRate;
}
}
quoteSvc.Update(ref ds);
this.resultHolder.Attach(ds);
int ct=0;
foreach(var dtl in ds.QuoteDtl)
{
dtl.SellingExpectedQty = (from qdd in Db.QuoteDtl where qdd.Company == dtl.Company && qdd.QuoteNum == sourceQuote select qdd).ToArray()[ct].SellingExpectedQty;
dtl.RowMod="U";
quoteSvc.ChangeSellingExpQty(ref ds);
ct++;
}
quoteSvc.Update(ref ds);
this.resultHolder.Attach(ds);
}