Solved
Can I test a manual input before save and/or calculate
Hi all
I like to check a manual data entry during save.
Is this possible?
Hi all
I like to check a manual data entry during save.
Is this possible?
Yes, this is possible, you need a SaveDataEventHandler Business rule for it. Here are some code samples:
First the basic function, only testing the input itself:
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As SaveDataEventHandlerArgs) As Object
Try
'------------------------
' Validate entered values
'------------------------
'Only test manual input
If args.NewDataCell.DataCellPK.OriginId = DimConstants.Forms Then
'---------------------------
'Account must be between 0-1
'---------------------------
Dim accountToTest As String = "60000"
'Test, if it is the account to test
If args.NewDataCell.DataCellPK.AccountId = BRApi.Finance.Members.GetMemberId(si, dimtype.Account.Id, accountToTest) Then
'The input amount
Dim dCellAmount As Decimal = args.NewDataCell.CellAmount
'Test the amount
If dCellAmount > 1 Or dCellAmount < 0 Then
'Throw an error to prevent the save
args.Cancel = True
Throw New Exception("Account: " & environment.NewLine & "Value entered must be between 0% and 100%" & environment.NewLine)
End If
End If
End If
Return args.DefaultReturnValue
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End FunctionAnd here a sample how to check if Forms and Import together have fit the test:
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As SaveDataEventHandlerArgs) As Object
Try
'------------------------
' Validate entered values
'------------------------
'Only test manual input
If args.NewDataCell.DataCellPK.OriginId = DimConstants.Forms Then
'---------------------------
'Account must be between 0-1
'---------------------------
Dim accountToTest As String = "60000"
'Test, if it is the account to test
If args.NewDataCell.DataCellPK.AccountId = BRApi.Finance.Members.GetMemberId(si, dimtype.Account.Id, accountToTest) Then
'Some objects as shortcuts
Dim originalCell As DataCell = args.NewDataCell
Dim originalCellPk As DataCellPk = originalCell.DataCellPK
'Some objects needed to retrieve the Data from the origin Import
Dim importCellPK As New DataCellPk(originalCellPk)
importCellPK.OriginId = dimconstants.Import
Dim sCubeName As String = brapi.Finance.Cubes.GetCubeInfo(si, importCellPK.CubeId).Cube.Name
Dim importDataUnitPk As New DataUnitPk(importCellPK)
Dim importDataBufferCellPk As New DataBufferCellPk(importCellPK)
'The input amount
Dim dCellAmount As Decimal = args.NewDataCell.CellAmount
'To test before adjustment retrieve the import datacell
Dim dataCellList As List(Of DataCell) = BRApi.Finance.Data.GetDataBufferDataCells(si, importDataUnitPk, importCellPK.ViewId, importDataBufferCellPk, False,True)
If dataCellList.Count = 1 Then
'If there is a result add it to the amount to test
dCellAmount += dataCellList(0).CellAmount
End If
'Test the amount
If dCellAmount > 1 Or dCellAmount < 0 Then
'Throw an error to prevent the save
args.Cancel = True
Throw New Exception("Account: " & environment.NewLine & "Value entered must be between 0% and 100%" & environment.NewLine)
End If
End If
End If
Return args.DefaultReturnValue
Catch ex As Exception
Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
End Try
End FunctionI hope this helps
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.