Debugging Business Rules ServiceNow

Debugging Business Rules

So far in this module, debugging has primarily been:
  • Using the Script Editor to find JavaScript syntax errors
  • Examining scripts to look for errors
  • Verifying the trigger is configured correctly
The strategies used so far are useful but are inadequate for fully debugging. Additional debugging strategies are:
  • System Logs
  • Debug Business Rules (Details)
  • JavaScript Debugger

System Logs

The scoped GlideSystem API has logging methods:
  • gs.info()
  • gs.warning()
  • gs.error()
  • gs.debug() (must be enabled)
All of the logging methods write to the System Log. Pass strings, variables that resolve to strings, or methods that resolve to strings into the logging methods.
gs.error("The value of the Short description field is " + short_description);
To view the log messages, open System Logs > System Log > Application Logs from the Application Navigator in the main ServiceNow browser window (not Studio).
Open the Application Log module from the Application Navigator
This script uses the info(), warn(), and error() methods.
The debug script
The log messages display the time created, verbosity level, message, scope, and script name. The application log
The scoped GlideSystem API also has a gs.debug() method. By default, debug information is not logged even if the gs.debug() method is used in a script. To enable the gs.debug() method, use the Application Navigator to open System Applications > Applications. Click on the application name to open the application record (Don’t click the Edit button for the application as that opens the application for editing in Studio.) In the Related Links section, click the Enable Session Debug link. This option writes debug information to the bottom of forms and not to the system log.
Opening an Application Record

Debug Business Rules (Details)

To debug the Condition field script, enable detailed Business Rule Debugging. Use the Application Navigator to open System Diagnostics >Session Debug > Debug Business Rules (Details). This module turns on logging of debug information to forms and lists. Open the form for a record of interest and force the Business Rule you are debugging to execute by doing whatever is necessary to trigger the Business Rule.
The Debug Business Rules (Details) module is the only way to debug Business Rule conditions
To turn off detailed Business Rule debugging, navigate to System Diagnostics > Session Debug > Disable All.