Forum Discussion

NidhiMangtani's avatar
NidhiMangtani
Contributor III
3 years ago

Automatic addition of FX Rate Types

Hi All,

I am trying to automate addition of FX Rate Types on a button click with some logic. 

Inserting values into FxRateType and AuditFxRateType using the below code snippet

------------------------------------

Public Sub AddCurrentFXRate(ByVal si As SessionInfo, ByVal api As Object, ByVal sCurrentOpsName As String, ByVal dt As DataTable)

Dim dbConnApp As DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)

Try

Dim sSQL As New Text.StringBuilder
Dim sFXRateTypeGuid As String = Guid.NewGuid.ToString

sSQL.AppendLine("INSERT INTO FxRateType
(UniqueID, Name, Description,
AccessGroupUniqueID, MaintenanceGroupUniqueID, XmlData)
VALUES ('" & sFXRateTypeGuid & "', '" & sCurrentOpsName & "', '" & sCurrentOpsName & "',
'" & dt.Rows(0)("AccessGroupUniqueID").ToString & "', '" & dt.Rows(0)("MaintenanceGroupUniqueID").ToString & "', ' ')")

sSQL.AppendLine("INSERT INTO AuditFxRateType
(AuditGuid, AuditSeqId, AuditUser,
AuditTime, AuditInsUpdateDel,
UniqueID, Name, Description,
AccessGroupUniqueID, MaintenanceGroupUniqueID, XmlData)
VALUES ('" & Guid.NewGuid.ToString & "', '1', '" & BRApi.Security.Authorization.GetUser(si, si.AuthToken.UserName).User.Name & "',
'" & DateTime.Now & "', '0',
'" & sFXRateTypeGuid & "', '" & sCurrentOpsName & "', '" & sCurrentOpsName & "',
'" & dt.Rows(0)("AccessGroupUniqueID").ToString & "', '" & dt.Rows(0)("MaintenanceGroupUniqueID").ToString & "', ' ')")

Using dbConnApp
dbConnApp.BeginTrans()
BRAPi.Database.ExecuteSql(dbConnApp, sSQL.tostring, False)
dbConnApp.CommitTrans()
End Using

Catch ex As Exception
dbConnApp.Dispose()
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try

End Sub

------------------------------------

The values get added into the tables fine, but the newly added rate type does not show in FX Rates interface even after refreshing the application. Would someone please guide what I am missing here?

5 Replies

  • NicolasArgente's avatar
    NicolasArgente
    Valued Contributor

    Hi Nidhi,
    I would not take this approach. I would use the native OS function Like 
      objXFResult = BRApi.Finance.Data.SetFxRate(si, objfxRate)

    For Each fxRate As Object In fxRates

                                                                'Process Average Rate

                                                                objFxRatePk.FxRateType = "AverageRate"

                                                                objFxRatePk.Time = period

                                                                objFxRatePk.SourceCurrency = sourceCurr

                                                                objFxRatePk.DestCurrency = fxRate.Key

                                                                objFxRate.FxRatePkUsingNames = objfxRatePk

                                                                objfxRate.Amount = fxRate.Value

                                                                objFxRate.HasData = True

                                                                objFxRate.IsInvalid = False



    • NidhiMangtani's avatar
      NidhiMangtani
      Contributor III

      Hi Nicolas, 

      Thanks for your response. I am not trying to set FX Rates. I am trying to create a new FX Rate Type on a button click.

  • Krishna's avatar
    Krishna
    Valued Contributor

    BRAPI is much better than SQL in some cases. I would recommend API functions vs SQL.

    • NidhiMangtani's avatar
      NidhiMangtani
      Contributor III

      Hello Krishna,

      Thanks for your response.  I had tried using SaveCustomDataTable to insert data in the mentioned tables. Since these are not custom tables, it did not work.