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

PrashantLearnIT
Giga Sage

Hi there, 

 

Explanation - 

 

There are different ways to debug code. The most common method is to output debug messages from scripts.

In order to output debug messages, debug statements must be added directly to the script.

 

A simple way to debug a custom or baseline script, without editing the actual script record, is to execute the script using Scripts - Background.

To navigate to Scripts - Background, do either of the following:

  • In the filter navigator, type sys.scripts.do and click Enter
  • Navigate to System Definition > Scripts - Background

1.jpg

 

Debug Server Scripts by adding Debug Statements

The most commonly used server-side debug methods are:

  • gs.log: used for global applications. This option writes messages to the Log [syslog] table and the localhost log. Also when using Background Scripts it prints the message to the browser screen. 
  • gs.print: used for global applications. This option writes messages to only the localhost log. Also when using Background Scripts it prints the message to the browser screen. 
  • gs.debug: used for scoped applications. This option writes messages to the Log [syslog] table and the localhost log. Also when using Background Scripts it prints the message to the browser screen.

If using gs.log (“message”,”source”), there is a second source parameter available called source. It is essential to use this second parameter as it will make it much easier to find the log output if you want to locate it in the Log [syslog] table.

It is recommended to put your debug statements near the failing area of the script or after a part of the script that you are trying to understand better. Add as much information in the message as needed to make the output more understandable.

 

If my content helped you in anyway, please mark this content as BOOKMARK, SUBSCRIBE & HELPFUL

 

Best Regards,

Prashant Kumar (LearnIT)

 

YouTube Channel LearnIT: https://www.youtube.com/@learnitwithprashant

Blog LearnIT: https://medium.com/@LearnITbyPrashant

Prashant Kumar LinkedIn: https://www.linkedin.com/in/learnitbyprashant/

ServiceNow Community Prashant Kumar - https://www.servicenow.com/community/user/viewprofilepage/user-id/19635