Creating Instances problem

fmhiguefmhigue Member Posts: 290
edited 2004-07-02 in Navision Attain
Guys I got the following code to identify between USA and MEXICO company. But I am getting an error message, the problem is cause because the instance but I do not know how to fix it.
This is the error message I am getting:

"There is no curency exchange rate within the filter". Filters: Currency Code:1, Starting Date: 07/02/04


Here is the code
.

END ELSE BEGIN //MEXICO COMPANY STARTING
USItem.CHANGECOMPANY(CompanyInformation.DSIUSCompanyName);

USCurrencyExchRate.CHANGECOMPANY(CompanyInformation.DSIUSCompanyName);
USItem.GET(Item."No.");

//Code to use Vendor Cost from US Company
IF USItem."Use Secondary Vendor" THEN BEGIN
VendorCost := USItem."Sec. Vendor Cost";
VendorCurr := USItem."Sec. Vendor Currency";
END ELSE BEGIN
VendorCost := USItem."Vendor Cost";
VendorCurr := USItem."Vendor Currency";
END;

//Code to change any currency to dollars
IF VendorCurr = 'USD' THEN
UnitCost := VendorCost
ELSE BEGIN
CurrencyFactor := USCurrencyExchRate.ExchangeRate(WORKDATE,VendorCurr);
UnitCost :=
ROUND(USCurrencyExchRate.ExchangeAmtFCYToLCY(WORKDATE,VendorCurr,VendorCost,CurrencyFactor));
END;


P.S. I am using Exchange Rate from the US company because we do not use those on Mexico.

Comments

  • fbfb Member Posts: 246
    If you follow the logic of the 'ExchangeRate' function, you will see it calls a function 'FindCurrency'. That function uses a new Currency Exchange Rate record (named 'CurrencyExchangeRate2[CacheNo]') to look up the appropriate exchange rate record.

    I believe that your problem is that CHANGECOMPANY has not been called on the 'CurrencyExchangeRate2[CacheNo]' record, so it is looking for records in the Mexico company. There are none, therefore the error message.

    This is the difficulty with cross-company stuff -- it is a lot more complex than we wish it would be.

    To solve your problem, you have to add a function to the Currency Exchange Rate record that you can call before using the 'ExchangeRate' function. This function should take the new company name, and store it in a global text variable. Then you must modify the 'FindCurrency' function so that it calls CHANGECOMPANY on 'CurrencyExchangeRate2[CacheNo]', if a new company name exists in the global text variable.

    Use with care... Test extensively... Be afraid, be very afraid...
  • fmhiguefmhigue Member Posts: 290
    Thank you a lot FB.

    You know something then I will considered synch vendor cost from US company to Mexico and if the vendor has any kind of currency different from USD. I will change those to USD

    Paco
Sign In or Register to comment.