The CreatorCon Call for Content is officially open! Get started here.

Track if Business Rule had fired on an insert (not real time)

Nisar3
Giga Guru

I've a BR defined on the incident table. It's a "after" BR and "insert" is true, "update" is false. There are no filter conditions defined on it, so expectation is that it will run on every insert.

 

I noticed that upon creation of a certain incident in the past, the code that's written in the BR did not execute. So is there a way to track if the said BR had actually been run? I can't use "Debug Business Rule" because this is not real time tracking - rather whether the BR executed in a past time or not.

 

I've the timestamp at which the incident was created. So if there's a place where BRs are also tracked, I can filter close to that timestamp. (pretty similar to the sysevent table where all events that were fired are logged). So hoping there is something for BRs as well.

1 ACCEPTED SOLUTION

Robbie
Kilo Patron
Kilo Patron

Hi @Nisar3,

 

Sadly, there isn't any built-in feature that provides a direct way to view retrospective execution history of a Business Rule. (Or not that I'm aware of. The stack trace is not available via system logs, transaction logs or even node logs).

 

The only thing you could possibly try is viewing the Audit History against the said record(s) and check the source column to see if a Business Rule made the change - however, based on the fact you don't see the change - this seems as if it won't really help - sorry.

 

As @Uncle Rob has mentioned and I'm sure other will, you have a couple of options for record moving forward (but sadly not retrospectively) by either using a simple gs.info() statement or leveraging the Script Debugger. (Check the Script Tracer which is a pretty cool tool to leverage for stack tracing).

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

View solution in original post

7 REPLIES 7

It will be interesting if ServiceNow support can provide any clarification - perhaps log a ticket on 'Support' and see if they can confirm (or if they have any insights not available to us).

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie

Hi @Robbie , Interestingly, I noticed the following error in the log table close the timestamp of incident creation.

 

JavaScript evaluation error on:
(function executeRule(current, previous /*null when async*/ ) {
	// the entire BR code is listed in this place
})(current, previous);
Root cause of JavaScriptException: java.lang.StackOverflowError 
: java.lang.StackOverflowError: 	com.glide.db.ConnectionWrapper.handleException(ConnectionWrapper.java:378)
	com.glide.db.AConnectionWrapperProxy.invoke(AConnectionWrapperProxy.java:36)
	com.glide.db.StatementWrapper.invoke(StatementWrapper.java:19)
	com.sun.proxy.$Proxy7.execute(Unknown Source)
	com.glide.db.DBI.executeStatement0(DBI.java:1521)
	com.glide.db.DBI.executeStatement(DBI.java:1442)
	com.glide.db.DBQueryExecutor.executeStatement(DBQueryExecutor.java:362)
	com.glide.db.DBQueryExecutor.executeStatement(DBQueryExecutor.java:349)
	com.glide.db.DBQueryExecutor.execute(DBQueryExecutor.java:107)
	com.glide.db.DBQuery.executeAsResultSet0(DBQuery.java:753)
	com.glide.db.DBQuery.executeAndReturnTable(DBQuery.java:666)
	com.glide.db.DBAction.executeNormal(DBAction.java:374)
	com.glide.db.DBAction.executeAndReturnException(DBAction.java:328)
	com.glide.db.RDBMSQueryContext.executeQuery(RDBMSQueryContext.java:42)
	com.glide.db.DBQuery.execute(DBQuery.java:3658)
	com.glide.db.meta.Table.queryBasic(Table.java:424)
	com.glide.db.meta.Table.query(Table.java:229)
	com.glide.script.GlideRecordITable.query(GlideRecordITable.java:115)
	com.glide.script.GlideRecord.query0(GlideRecord.java:3476)
	com.glide.script.GlideRecord.query(GlideRecord.java:3194)
	com.glide.script.GlideRecord.jsFunction_query(GlideRecord.java:3077)
	jdk.internal.reflect.GeneratedMethodAccessor47.invoke(Unknown Source)
	java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	java.base/java.lang.reflect.Method.invoke(Method.java:566)
	org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138)
	org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:677)
	org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614)
	org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2649)
	org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1518)
	org.mozilla.javascript.Interpreter.interpret(Interpreter.java:830)
	org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:160)

 

I cannot make sense of it but perhaps trying my luck here with you to see if by any chance you or someone else have come across similar error messages.

Hi @Nisar3,

 

This is one way to know whether the Business Rule was call - when an error is thrown, the error will be logged.

It's a little hard to decipher what's going on here - it's all quite abstract.

 

Can you maybe share the code that's written in the Business Rule or explain the high level requirement maybe?

Sadly though, circling back to my original response and your question - there doesn't seem to be a way to retrospectively view the execution history.

 

To help others (and for me to gain recognition for my efforts), please mark this response correct by clicking on Accept as Solution and/or Kudos.




Thanks, Robbie