how to debug a business rule

VVpackers
New Contributor

An allocation business rule is not allocating the rates properly . Hence we would like to debug the business rule and also figure out which intersections are passed and what is the value and allocation rate used in allocation calculation .

This allocation process involves a formula in UD7 member .

Please advise how to see the messages used in api.logmessage . Should we need to create a dashboard to capture the messages that are logged while running the allocations. Again, we are looking for which members used and the value / rate used to allocate.

1 ACCEPTED SOLUTION

OS_Pizza
Contributor III

@VVpackersYou can use the below methodology to start debugging your rule. I have read the below tip from this community.

	1) Simplifying Log Message 
	
	Define a Boolean Constant LogSwitch

		Public Const LogSwitch As Boolean = True 
		
		True- To turn on logging for your business rule
		False - To turn off logging  for your business rule
		
		Use the below statement when writing a log 
		If LogSwitch = True Then brapi.ErrorLog.LogMessage(si, "My Workflow name is " &Workflow )


Also, To Log everything in a single string use the below format -

		Dim log As String = String.Empty
		
		'Append to “log” throughout business rule
		
		log += “Message 1” & VbCrLf   '<— VbCrLf is a .Net constant for “New Line”
		
		log += “Message 2” & VbCrLf 
		
		
		'At the very end of Business Rule I write the log variable to the ErrorLog.
BRApi.ErrorLog.LogMessage(si, log)

 

View solution in original post

11 REPLIES 11

RobbSalzmann
Valued Contributor

You can write debug messages to the log with BRApi.ErrorLog.LogMessage(si,"Message to log")

RobbSalzmann_0-1683148526549.png

 

JackLacava
Community Manager
Community Manager

Anything written with Api.LogMessage or BRApi.ErrorLog.LogMessage will appear in the Error Log, which can be found in the System pane - NOT in the Task Activity Log.

OS_Pizza
Contributor III

@VVpackersYou can use the below methodology to start debugging your rule. I have read the below tip from this community.

	1) Simplifying Log Message 
	
	Define a Boolean Constant LogSwitch

		Public Const LogSwitch As Boolean = True 
		
		True- To turn on logging for your business rule
		False - To turn off logging  for your business rule
		
		Use the below statement when writing a log 
		If LogSwitch = True Then brapi.ErrorLog.LogMessage(si, "My Workflow name is " &Workflow )


Also, To Log everything in a single string use the below format -

		Dim log As String = String.Empty
		
		'Append to “log” throughout business rule
		
		log += “Message 1” & VbCrLf   '<— VbCrLf is a .Net constant for “New Line”
		
		log += “Message 2” & VbCrLf 
		
		
		'At the very end of Business Rule I write the log variable to the ErrorLog.
BRApi.ErrorLog.LogMessage(si, log)

 

Thanks for all your ideas . I am also trying to get messages out of a formula used in a UD7 member. How can I grab messages out of it ? Because I can see the messages from a business rule and not seeing from the messages I put in UD7 member formula. 

Can you share some screenshots ?

 

Make sure your UD7 member is assigned to a pass in the Formula Type property, or the formula won't run at all. Depending on how you're triggering this, you might need to set the Is Consolidated property too.

As @OS_Pizza said, you want to run your action "With Logging" and then look into the Task Activity Log, expanding Child Steps to verify if the formula is ever invoked and where:

JackLacava_0-1683215239670.png

Once you're sure the formula is invoked, you can start peppering it with LogMessage calls, which will appear in System Pane -> Error Log.

 

RobbSalzmann
Valued Contributor

I use 

 

Sub Debug(si As SessionInfo, message As String)
	isTestOrQa = True
	If(isTestOrQa)Then BRApi.ErrorLog.LogMessage(si, message)
End Sub

 

RobbSalzmann_1-1683208639523.png

RobbSalzmann_2-1683208715477.png

 

 

 

Same for me except that since we're running it through our own debugging function I add as much useful info as I can (which would be a pain if repeating for every manual logmessage. For example, a better timestamp that allows sub-second sorting.

VVpackers
New Contributor

VVpackers_0-1683211313904.png

 

1. When you run Calculate.Run calculate using logging. This will show you if your formulae ran or not.

If it doesnt show up , that means your formulae never ran and the log entry wont be there.

2. You need to share the screenshot of your allocation rule that you have written and the portion where you     are trying to debug.

chul
Contributor III

If API is available, do NOT use BRAPI. I understand that this is for debugging but it does add time to calculations. The negative performance impact of accidentally leaving the switch turned on will be heavier if BRAPI is used.

cds