Hi Henning,
Thanks for the reply. This is just what i was trying to achive. But i couldn't make it work. Tried with a FinanceFunctionType.FxRate and also FinanceFunctionType.Translate but couldnt get the values translated to the prior year rate.
I finally created two exchange rate tables PYAverageRate amd PYClosingRate and created a Extensibility Rule that copies Rates from AverageRate and ClosingRate Tables to the new ones switching back one year.
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As ExtenderArgs) As Object
Try
Me.SetPriorYearRates(si, "PriorYearAverageRate", "AverageRate")
Me.SetPriorYearRates(si, "PriorYearClosingRate", "ClosingRate")
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End Function
#Region "PriorYearRates"
Public Function SetPriorYearRates(ByVal si As SessionInfo, ByVal targetRateTable As String, ByVal sourceRateTable As String)
Try
'****************************************************************************************************
'Define the target Rate Type:
Dim fxRateTypeTarget As String = targetRateTable
'Define the source Rate Type:
Dim fxRateTypeSource As String = sourceRateTable
'Define the target period year:
Dim myWorkflowUnitPk As WorkflowUnitPk = BRApi.Workflow.General.GetWorkflowUnitPk(si)
Dim workflowTimeTarget As String = BRApi.Finance.Time.GetNameFromId(si, myWorkflowUnitPk.TimeKey).Substring(0,4)
'Define the source period year:
Dim workflowTimeSource As String = BRApi.Finance.Time.GetNameFromId(si, BRApi.Finance.Time.AddYears(si, myWorkflowUnitPk.TimeKey, -1)).Substring(0,4)
'BRApi.ErrorLog.LogMessage(si, "Target Time = " & workflowTimeTarget & ", Souce Time = " & workflowTimeSource)
'Define the list of periods:
Dim periods As String() = {"M1","M2","M3","M4","M5","M6","M7","M8","M9","M10","M11","M12"}
'Define the list of source currencies:
Dim currencyStr As String = BRApi.Utilities.GetApplicationProperties(si).CurrencyFilter
Dim sourceCurrencies As List(Of String) = StringHelper.SplitString(currencyStr,",",StageConstants.ParserDefaults.DefaultQuoteCharacter)
'Loop periods:
For Each period As String In periods
'Loop source currencies:
For Each sourceCurrency As String In sourceCurrencies
'Define destination currencies:
Dim destinationCurrency As String = Currency.USD.Name
'Get source's rate type, time period, source and destination currencies:
Dim objFxRatePkUsingNamesSource As New FxRatePkUsingNames(fxRateTypeSource,workflowTimeSource & period,sourceCurrency,destinationCurrency)
Dim objFXRateUsingNamesSource As FXRateUsingNames = BRApi.Finance.Data.GetStoredFxRate(si, objFxRatePkUsingNamesSource)
If objFXRateUsingNamesSource.Amount > 0 Then
'Get target's rate type, time period, source and destination currencies:
Dim objFxRatePkUsingNamesTarget As New FxRatePkUsingNames(fxRateTypeTarget,workflowTimeTarget & period,sourceCurrency,destinationCurrency)
'Define the FX rate value (set HasData to True and IsInvalid to False in order to submit the FX rate successfully):
Dim objFxRateUsingNamesTarget As New FxRateUsingNames(objFxRatePkUsingNamesTarget, objFXRateUsingNamesSource.Amount, True, False)
'Submit the rate if exists:
brapi.Finance.Data.SetFxRate(si,objFxRateUsingNamesTarget)
End If
Next
Next
'****************************************************************************************************
Return Nothing
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
#End Region
End Try
End Function