How to create a debug business rule to capture stack tracesIssue <!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Create a debug business rule that captures stack traces that can help you identify and troubleshoot which code is inserting, updating, or deleting records unexpectedly. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } All supported releases Resolution<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Before you begin Before creating a debug business rule, define a hypothesis for what you want to capture. Logging everything slows performance and produces excessive log data. An effective debug business rule depends on restrictive conditions. Examples of restrictive conditions: ScenarioTableOperationConditionMany new records created by a specific useru_testinsertCreated by = Abel TuterMany updates made by a specific useru_testupdateUpdated by = David LooMany records created with a specific valueu_testinsertName = ABCDE Resolution Create the debug business rule (global scope) The following script works in the global scope only. Customize the conditions based on your troubleshooting hypothesis. (function executeRule(current, previous /*null when async*/) {// Add your code heregs.log('***** DEBUG - op:'+ current.operation() + ", sess:" + gs.getSessionID() + ", time:" + new Date().getTime() + ', sys_id:' + current.sys_id + ' - \n' + GlideLog.getStackTrace(new Packages.java.lang.Throwable()), 'Stacktrace Debug');})(current, previous); Information logged: FieldDescriptionoperationThe database operation: insert, update, or deletesessionIDUseful when searching transaction logs or node logstimeTimestamp when the business rule was invokedsys_idUseful when searching the system log for business rule outputstack traceThe full stack trace when the business rule was invoked View the logs To view the debug output, query the System Log [syslog] table where Source is "Stacktrace Debug". For example: https://<instance_name>.service-now.com/syslog_list.do?sysparm_query=source%3DStacktrace%20Debug Additional search options: Search the logs where the message contains the sys_id of the record.When multiple stack traces are logged, searching by sys_id helps locate a specific entry. Note: To find the stack trace for deleted records, save the sys_id before the record is removed. Create the debug business rule (scoped applications) The global scope script does not work in scoped applications because Packages calls cannot be used within a scoped application. To work around this limitation, create a global script include that the scoped business rule can call. Step 1: Create a global script include Create a script include named StackTrace with Accessible from set to From all scopes. var StackTrace = Class.create();StackTrace.get = function() { return GlideLog.getStackTrace(new Packages.java.lang.Throwable());}; Step 2: Create the scoped business rule Use gs.info instead of gs.log because gs.log is only available in the global scope. (function executeRule(current, previous /*null when async*/) {// Add your code heregs.info('***** DEBUG - op:'+ current.operation() + ", sess:" + gs.getSessionID() + ", time:" + new Date().getTime() + ', sys_id:' + current.sys_id + ' - \n' + global.StackTrace.get(), 'Stacktrace Debug');})(current, previous);