If you want to convert an amount from a foreign currency into the local currency, you can call the function ExchangeAmtFCYToLCY that you find in the Curreny Exchange Rate table (330).
If you want to find an example of its use, you can see the OnValidate trigger of the Outstanding Amount field of Sales Line table (37).
Dunno if this is the smoothest way to obtain your filter task, but it should work
IF ExchRateRec.GET(MyCurrCode,PostDate) THEN BEGIN
// There is an exchange rate on the actual date, and you use that one…
END ELSE BEGIN
// You’ll now gradually extend your daterange by 1 day, until you find an exchange rate to use.
ExchRateRec.SETRANGE(“Currency Code”,MyCurrCode);
FilterFromDate := PostDate;
FilterToDate := PostDate;
FOR i := 1 TO 100 DO BEGIN // 100 is the max number of days you can extend the daterange.
FilterFromDate := CALCDATE(’<-1D>’,FilterFromDate);
FilterToDate := CALCDATE(’<1D>,FilterToDate);
ExchRateRec.SETRANGE(“Starting Date”,FilterFromDate,FilterToDate);
IF ExchRateRec.FINDSET(FALSE,FALSE) THEN BEGIN
// You’ve now found the exchange rate with the starting date closest to the posting date.
// NOTE! If you’ve got 2 exchange rates within the daterange, using FINDSET will always give you the earliest on,
// whereas if you want to latest one, you have to use FINDLAST
END;
END;
END;
Wouldn’t this give him the last record before posting date?
I understood that he wanted the closet one, no matter if it’s before or after posting date.
So if the posting date is nov. 7., the rate used should be 1100.
I agree with u David, that it’s not logical to use the nearest in exchange rates.
The name of the date field (Starting Date) should give a hint that u want the last before.