GetDataBuffer Usage
Example using GetDataBuffer with Data Buffer Math in a working formula:
'Alternate way to api.Data.Calculate("A#DataBufferMath:UD2#None = A#60999:UD2#Top - A#54500:UD2#Top"). May have better performance impact.
'Run only for Local Currency and Base Entities
If (Not api.Entity.HasChildren()) And (api.Cons.IsLocalCurrencyforEntity()) Then
'Declare Variable for Destination Buffer
Dim destinationInfo As ExpressionDestinationInfo = api.Data.GetExpressionDestinationInfo("A#DataBufferMath:UD2#None")
'Get Source Data Buffer for Net Sales
Dim netSales As DataBuffer = api.Data.GetDataBuffer(DataApiScriptMethodType.Calculate, "RemoveNoData(A#60999:UD2#Top)", destinationInfo)
'Get Source Data Buffer for Operating Expenses
Dim operatingExpenses As DataBuffer = api.Data.GetDataBuffer(DataApiScriptMethodType.Calculate, "RemoveNoData(A#54500:UD2#Top)", destinationInfo)
'Create New Data Buffer With the End Result of Net Sales - Operating Expenses
Dim dataBufferExample As DataBuffer = (netSales - operatingExpenses)
'Set the Destination Data Buffer
api.Data.SetDataBuffer(dataBufferExample, destinationInfo)
End If
Example using GetDataBuffer and SetDataBuffer in Business Rule Using Sub Routine in a working formula:
Case Is = FinanceFunctionType.Calculate
'Execute Sub Routine in the Function to Return Results
Me.CalculateBonusUsingGetDataBuffer(api)
Private Sub CalculateBonusUsingGetDataBuffer(ByVal api As FinanceRulesApi)
Try
'Define Destination Data Buffer for left side of the equation
'Will copy to A#Bonus while processing the data buffer in memory
Dim destinationInfo As ExpressionDestinationInfo = api.Data.GetExpressionDestinationInfo("")
'Read the numbers for A#Salary into a source Data Buffer
Dim sourceDataBuffer As DataBuffer = api.Data.GetDataBuffer(DataApiScriptMethodType.Calculate, "A#Salary", destinationInfo)
'Check to make sure the source Data Buffer exists
If Not sourceDataBuffer Is Nothing Then
'Create a new data buffer for the result cells
Dim resultDataBuffer As DataBuffer = New DataBuffer()
'Loop over the source cells in the source Data Buffer
For Each sourceCell As DataBufferCell In sourceDataBuffer.DataBufferCells.Values
'Only process cells that have data and cell amount that is greater than 0
If ((Not sourceCell.CellStatus.IsNoData) And (sourceCell.CellAmount > 0.00)) Then
'Create new data buffer cells from the filtered source cells from source Data Buffer
Dim resultCell As New DataBufferCell(sourceCell)
'Define A#Bonus as the target account to copy to
'Multiply data cell amounts by 5%
'Set the manipulated data cells to the data buffer
resultCell.DataBufferCellPk.AccountId = api.Members.GetMemberId(DimType.Account.Id, "Bonus")
resultCell.CellAmount = sourceCell.CellAmount * 0.05
resultDataBuffer.SetCell(api.SI, resultCell)
End If
Next
'Save the results to the destination data buffer
api.Data.SetDataBuffer(resultDataBuffer, destinationInfo)
End If
Catch ex As Exception
Throw ErrorHandler.LogWrite(api.si, New XFException(api.si, ex))
End Try
End Sub


