Breaking Change in the OpportunitySnapshot.ascx.cs for Infor CRM 8.3x

Prior to 8.3, the ExchangeRate table in the Infor CRM database used the column CurrencyCode as the primary ID of the table. Because of this in the custom Opportunity Smart part OpportunitySnapshot, there was a method to get the exchange rate called GetExchangeRateData that used the GetById method to return the ExchangeRate record based on passing the currency code in:

IExchangeRate er = EntityFactory.GetById<IExchangeRate>(String.IsNullOrEmpty(_exchangeRateCode) ? "USD" : _exchangeRateCode);
_exchangeRate = er.Rate.GetValueOrDefault(1);

Because an Id column (ExchangeRateId) was introduced in 8.3, the code that used to work pre 8.3 no longer works and the second line where the er.Rate.GetValueOrDefault() is called results in a null reference exception.

Instead now in 8.3 the code now looks like this:

var er = EntityFactory.GetRepository<IExchangeRate>()
                .FindFirstByProperty("CurrencyCode", String.IsNullOrEmpty(_exchangeRateCode) ? "USD" : _exchangeRateCode);
_exchangeRate = er.Rate.GetValueOrDefault(1);

This means that you can’t just bring forward this custom smart part from a pre-8.3 system. You need to retrofit this undocumented change.

While you are at it, you should also add error trapping to ensure that you still dont get a null reference exception if an currency code is passed in that does not exist in the ExchangeRate table. The proper code should look like:

var er = EntityFactory.GetRepository<IExchangeRate>()
                .FindFirstByProperty("CurrencyCode", String.IsNullOrEmpty(_exchangeRateCode) ? "USD" : _exchangeRateCode);
if(er!=null) _exchangeRate = er.Rate.GetValueOrDefault(1);
ABOUT THE AUTHOR

Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) news and product updates!

You have Successfully Subscribed!