Logging message to error log for first iteration of the business rule

bk0615
New Contributor

I am launching a business rule through a Data Management job for all the base entities of certain rollup, i.e, TopEntity.base. As expected, the code loops through all the base entities and executes the code. I want to log the POV passed in for troubleshooting purposes. When I log the message, it logs it for each iteration of the code. Is there a way to only log the message for the first iteration of the code to avoid logging multiple entries to the log? As a workaround, I have hard-coded a specific entity, but if I can avoid hard-coding that would be ideal. Below is the code snippet:

#Region "Clear_Calculated_Data"
If args.CustomCalculateArgs.FunctionName.XFEqualsIgnoreCase("ClearCalculatedData") Then
Dim sTime As String = api.Pov.Time.Name
Dim sScenario As String = api.Pov.Scenario.Name
Dim sEntity As String = api.Pov.Entity.Name
 
'Logging Info for Troubleshooting Purposes - Using Single Entity so message is not logged multiple times
If sEntity = "Ent_005" Then 
Brapi.ErrorLog.LogMessage(si, "Data Clear: Time: " & sTime &  ",Scenario: " &sScenario)
End If
api.Data.ClearCalculatedData(True,True,True,True,"A#TotNS_Adj, A#TotCOG_Adj",,,,,,,,,,"U7#Inp",)
End If
#End Region

 

3 REPLIES 3

Big_Rick_CPM
New Contributor III

I think you are going to want to use the Globals object. With this, you should create a counter variable and set that variable into globals for each entity to refer to and increment. 

RobbSalzmann
Valued Contributor

If this is for troubleshooting, create a parameter such as pm_iter. Set it to 0. Then in your br set it to 1 near the end of the code.  Put logic around your logging to check if pm_iter = 0.  This way it will only log the first time. 

 

Software Architect
MindStream Analytics
"Difficult done right away. Impossible takes a bit longer"

I believe since this is setup in a DM sequence doing TopEntity.Base, @bk0615, will also need to set the variable in to the globals object so other entities can refence the value.