Forum Discussion

maxpaul's avatar
maxpaul
New Contributor
1 day ago

I want to Validate that the Data is cleared and validate the calculate

Hi all - 

We have a Labor Allocation Process that runs manually which we have seen some silent failures occur through our Api Calculate or Api Clear data. I am attempting to go through our business rules and add more complex logging to get a better understanding where/when these things occur. 

 

Lets say I had this code block..

Dim sourceDims As String = "U2#None:U3#None:O#Import:I#None:F#None:V#Periodic:C#USD"
Dim destinationDims As String = "U2#None:U3#None:O#Import:I#None:F#None:V#Periodic:C#USD"
 
If args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("Copy3rdPartyImportData") Then
'Only run for the Base Entities and local currency
If (Not api.Entity.HasChildren()) And (api.Cons.IsLocalCurrencyForEntity())
'Get the current scenario Name
Dim curScenarioName As String = api.Pov.Scenario.Name
If curScenarioName = "Rpt_Mar" Then
'Clear previously calculated data
api.Data.ClearCalculatedData(True, True, True, True,"A#3PFB_Capital","O#Import","I#None","V#Periodic","C#USD")
api.Data.ClearCalculatedData(True, True, True, True,"A#3PFB_Expense","O#Import","I#None","V#Periodic","C#USD")
api.Data.ClearCalculatedData(True, True, True, True,"A#Travel_Capital","O#Import","I#None","V#Periodic","C#USD")
api.Data.ClearCalculatedData(True, True, True, True,"A#Travel_Expense","O#Import","I#None","V#Periodic","C#USD")
 
'Seed Current Scenario with previous imported 3rd party data
api.Data.Calculate("S#" & curScenarioName & ":A#3PFB_Capital:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#3PFB_Capital:" & sourceDims & ")",True)
api.Data.Calculate("S#" & curScenarioName & ":A#3PFB_Expense:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#3PFB_Expense:" & sourceDims & ")",True)
api.Data.Calculate("S#" & curScenarioName & ":A#Travel_Capital:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#Travel_Capital:" & sourceDims & ")",True)
api.Data.Calculate("S#" & curScenarioName & ":A#Travel_Expense:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#Travel_Expense:" & sourceDims & ")",True)

 

I have tried: 

Dim srcCap As Decimal = api.Data.GetDataCell("S#Rpt_Nov:A#3PFB_Capital:U1#TotUD1:U2#None:U3#None:U4#TotUD4:U5#None:U6#None:U7#None:U8#None:O#Import:I#None:F#None:V#Periodic:C#USD:E#CHN000").CellAmount

BRApi.ErrorLog.LogMessage(si, "SOURCE 3PFB_Capital=" & srcCap.ToString("N2"))

 

Which results in 0.

api.Data.Calculate(formula1, True)

Dim verify1 As Decimal = api.Data.GetDataCell("S#Rpt_Dec:A#3PFB_Capital:U1#TotUD1:U2#None:U3#None:U4#TotUD4:...E#" & api.Pov.Entity.Name).CellAmount

BRApi.ErrorLog.LogMessage(si, "DEST read-back=" & verify1.ToString("N2"))

same with something like this.

1 Reply

  • MarcusH's avatar
    MarcusH
    Valued Contributor

    I think the problem is the Origin member for the destination. Change that to Forms. Also I would not specify a specific currency on the Consolidation member unless you are transferring translated values. Either set it to C#Local or leave it out completely. If you still want to debug I would use a data buffer to get the before and after data something like this:

    Dim listAccounts As New List(Of String) From {"3PFB_Capital", "3PFB_Expense", "Travel_Capital", "Travel_Expense" }
    Dim debugNumberLines as integer = 100
    For Each thisAcc As String In listAccounts
    	Dim srcDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula($"RemoveZeros(S#Rpt_Feb:A#{thisAcc}:" & sourceDims & ")", , False)
    	srcDataBuffer.LogDataBuffer(api, $"Source data for account [{thisAcc}]", debugNumberLines)
    Next
    
    'Seed Current Scenario with previous imported 3rd party data
    api.Data.Calculate("S#" & curScenarioName & ":A#3PFB_Capital:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#3PFB_Capital:" & sourceDims & ")",True)
    api.Data.Calculate("S#" & curScenarioName & ":A#3PFB_Expense:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#3PFB_Expense:" & sourceDims & ")",True)
    api.Data.Calculate("S#" & curScenarioName & ":A#Travel_Capital:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#Travel_Capital:" & sourceDims & ")",True)
    api.Data.Calculate("S#" & curScenarioName & ":A#Travel_Expense:" & destinationDims & " = RemoveZeros(S#Rpt_Feb:A#Travel_Expense:" & sourceDims & ")",True)
    
    For Each thisAcc As String In listAccounts
    	Dim tgtDataBuffer As DataBuffer = api.Data.GetDataBufferUsingFormula($"RemoveZeros(S#{curScenarioName}:A#{thisAcc}:" & destinationDims & ")", , False)
    	tgtDataBuffer.LogDataBuffer(api, $"Calculated data for account [{thisAcc}]", debugNumberLines)
    Next