Data Buffer to delete the data on the LHS (Target Account) ?????
All - Could you please review code is make sense from performance. I am trying to be checking the target Account is <> 0 then it will delete the source value and overwrite the target value. PLease review and let me know if I can use some kind of EVAl or Data Buffer???
If Not api.Entity.HasChildren Then
If Not api.Cons.IsLocalCurrencyForEntity Then
api.Data.Calculate("A#Target:F#EndBalInput=RemoveZeros(Eval(A#Source))",AddressOf OnEvalDataBuffer)
End If
End If
Private Sub OnEvalDataBuffer(ByVal api As FinanceRulesApi, ByVal evalName As String, ByVal eventArgs As EvalDataBufferEventArgs)
eventArgs.DataBufferResult.DataBufferCells.Clear
If Not eventArgs.DataBuffer1 Is Nothing Then
For Each Cell As DataBufferCell In EventArgs.DataBuffer1.DataBufferCells.Values
If Cell.CellAmount <> 0 Then
'api.LogMessage(cell.CellAmount.ToString)
api.Data.ClearCalculatedData(True,True,True,"A#Target")
eventargs.DataBufferResult.SetCell(api.SI,cell)
' Else
' api.LogMessage("NODATA")
End If
Next
End If
End Sub
Hi Krishna,
First off, the main api.data.calculate call isn't balanced where you have F#EndBalInput on the left side of the equation but not on the right. The right side should be A#Source:F#EndBalInput so that the data buffers align on both sides of the equation.
Second, I'm assuming that in this exercise, you are only want to modify Target intersections if the same intersection in Source has a non-zero value? If this is the case, I don't think you even need to run an Eval at all since you are using the RemoveZeros function on the right side of the equation. Target will only be updated with the Source data buffer that already excludes cells with 0 value.
Third, in the Eval sub, the line api.Data.ClearCalculatedData doesn't make sense in the context of you looping through each databuffer cell for Source account. You are basically clearing all calculated data cells for A#Target regardless of the current cell you're loop is evaluating. I think you would need to refine the member filter to include members of other dimensions so as to clear the intersection that is aligned with the source cell. For example:
For Each Cell As DataBufferCell In EventArgs.DataBuffer1.DataBufferCells.Values If Cell.CellAmount <> 0 Then Dim ud1Member as String = cell.GetUD1Name(api) Dim ud2Member as String = cell.GetUD2Name(api) api.Data.ClearCalculatedData(True,True,True,"A#Target:UD1#" & ud1Member & ":UD2#" & ud2Member) eventargs.DataBufferResult.SetCell(api.SI,cell) End If Next
Hope this helps!