File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Server-Side Components/Script Includes/NonProdLogUtils Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ To create a logging utility in a ServiceNow Script Include that only logs in non-production environments, you can follow these steps:
2+
3+
4+ Create a new Script Include.
5+ Define a utility class with a logging function.
6+ Inside the function, get the instance name and use conditional logic to check if it matches the production instance name.
7+ If the instance is non-production, execute the logging command.
8+ Call this utility from other server-side scripts.
9+
10+
11+ This method centralizes your logging logic, making it easy to manage.
12+ Step 1: Create the Script Include
13+ In the main navigation, type Script Includes and select it under System Definition.
14+ Click New to create a new record.
15+ Fill out the form with the following details:
16+ Name: LoggingUtils
17+ Accessible from: All application scopes (This allows you to call the function from anywhere).
18+ Client callable: Unchecked (This is a server-side utility).
19+
20+
21+
22+
23+ // Instantiate the Script Include
24+ var logUtil = new LoggingUtils();
25+
26+ // Use the log() function to log a message
27+ logUtil.log('Hackertoberfest', 'info');
You can’t perform that action at this time.
0 commit comments