From a3e84af8c56f3c7d15fc3fb05e7c942417c8c578 Mon Sep 17 00:00:00 2001 From: Greg <67873454+1shabby@users.noreply.github.com> Date: Wed, 8 Oct 2025 00:05:32 -0500 Subject: [PATCH 1/3] Clean Script Include Framework This is a script include framework that I utilize in my day to day work to help reduce the number of extraneous logs that live on our instances as well as keep the code clean and readable so that new developers on the projects can quickly understand the purpose of the methods and how to utilize them. I've added some mock methods to the script include in code.js and at the bottom of the file I added an example of what it looks like calling the script include from a server script. --- .../Script Includes/Clean Framework/Code.js | 72 +++++++++++++++++++ .../Script Includes/Clean Framework/README.md | 1 + 2 files changed, 73 insertions(+) create mode 100644 Server-Side Components/Script Includes/Clean Framework/Code.js create mode 100644 Server-Side Components/Script Includes/Clean Framework/README.md diff --git a/Server-Side Components/Script Includes/Clean Framework/Code.js b/Server-Side Components/Script Includes/Clean Framework/Code.js new file mode 100644 index 0000000000..2f8fdcd8c9 --- /dev/null +++ b/Server-Side Components/Script Includes/Clean Framework/Code.js @@ -0,0 +1,72 @@ +Script Include Definition: + +var super_utils = Class.create(); +super_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { + initialize: function(debug, noDebugMethods) { + this.debug = false; // Flag to allow debug or not on this script include + this.noDebugMethods = []; // Array of methods to not log from + + if (debug) { + this.debug = debug; + } + + if (noDebugMethods) { + this.noDebugMethods = noDebugMethods.split(','); + } + + // Global Variables For Use In Script + this.CASETYPE1 = '[casetype 1 table]'; + this.CASETYPE2 = '[casetype 2 table]'; + + }, + + /** + * Description: Takes in a method name and message and logs the message in gs.info if debug and method isn't in noDebugMethods + * Parameters: [string] - methodName: name of method calling log. + [string] - msg: message being called in log. + * Returns: None. + */ + + log: function(methodName, msg) { + if (this.debug && this.noDebugMethods.indexOf(methodName) === -1) { + gs.info('[Super_Utils - ' + methodName + '] ' + msg); + } + }, + +/** + * Description: Takes in an input then gets all records where field is input and created by is "iloveearl" + * Parameters: [string] - input: Value that we're querying on. + * Returns: [array][object] - arr: Array of GlideRecord objects matching the conditions. + */ + +superFunction: function(input){ + var arr = []; + var gr = new GlideRecord(this.CASETYPE1); + gr.addQuery('sys_created_by', 'iloveearl'; + gr.addQuery('field',input); + gr.query(); + + while(gr.next()){ + arr.push(gr); + this.log("superfunction", "Created on: " + sys_created_on); + } +return arr; +}, + +/** + * Description: This is a very important method... + * Parameters: None. + * Returns: Logs a very important message. + */ + +superFunction2: function(){ + for (var i = 1; i <= 100000; i++) { + this.log("superFunction2", "ILOVEEARL); + } + } +}, + type: 'super_utils' +}); + +Calling Script Include Via Server Side Script: +var utils = new scope.super_utils('true', 'superFunction2'); \ No newline at end of file diff --git a/Server-Side Components/Script Includes/Clean Framework/README.md b/Server-Side Components/Script Includes/Clean Framework/README.md new file mode 100644 index 0000000000..a626718452 --- /dev/null +++ b/Server-Side Components/Script Includes/Clean Framework/README.md @@ -0,0 +1 @@ +This is a generally useful framework for script includes that in use in my day to day work as well as personal projects on my PDI. It allows you to easily enable logs when calling whichever method you want to use when developing and debugging, then easily disable them by no longer passing in the initilization debug true param or setting it to false in your call. It's very sleek and I highly recommend using it wherever you can to help keep a clean codebase. I also included some examples of how I docment each of my methods. I find it to be helpful when dealing with complex methods I haven't touched in awhile as well as making it easy for new developers to look at the code and hit the ground running quickly. \ No newline at end of file From 3a56f60cbd53f26495ebe9d495d33b1e1d4bc3c0 Mon Sep 17 00:00:00 2001 From: Greg <67873454+1shabby@users.noreply.github.com> Date: Thu, 9 Oct 2025 22:33:59 -0500 Subject: [PATCH 2/3] Delete Server-Side Components/Script Includes/Clean Framework directory --- .../Script Includes/Clean Framework/Code.js | 72 ------------------- .../Script Includes/Clean Framework/README.md | 1 - 2 files changed, 73 deletions(-) delete mode 100644 Server-Side Components/Script Includes/Clean Framework/Code.js delete mode 100644 Server-Side Components/Script Includes/Clean Framework/README.md diff --git a/Server-Side Components/Script Includes/Clean Framework/Code.js b/Server-Side Components/Script Includes/Clean Framework/Code.js deleted file mode 100644 index 2f8fdcd8c9..0000000000 --- a/Server-Side Components/Script Includes/Clean Framework/Code.js +++ /dev/null @@ -1,72 +0,0 @@ -Script Include Definition: - -var super_utils = Class.create(); -super_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { - initialize: function(debug, noDebugMethods) { - this.debug = false; // Flag to allow debug or not on this script include - this.noDebugMethods = []; // Array of methods to not log from - - if (debug) { - this.debug = debug; - } - - if (noDebugMethods) { - this.noDebugMethods = noDebugMethods.split(','); - } - - // Global Variables For Use In Script - this.CASETYPE1 = '[casetype 1 table]'; - this.CASETYPE2 = '[casetype 2 table]'; - - }, - - /** - * Description: Takes in a method name and message and logs the message in gs.info if debug and method isn't in noDebugMethods - * Parameters: [string] - methodName: name of method calling log. - [string] - msg: message being called in log. - * Returns: None. - */ - - log: function(methodName, msg) { - if (this.debug && this.noDebugMethods.indexOf(methodName) === -1) { - gs.info('[Super_Utils - ' + methodName + '] ' + msg); - } - }, - -/** - * Description: Takes in an input then gets all records where field is input and created by is "iloveearl" - * Parameters: [string] - input: Value that we're querying on. - * Returns: [array][object] - arr: Array of GlideRecord objects matching the conditions. - */ - -superFunction: function(input){ - var arr = []; - var gr = new GlideRecord(this.CASETYPE1); - gr.addQuery('sys_created_by', 'iloveearl'; - gr.addQuery('field',input); - gr.query(); - - while(gr.next()){ - arr.push(gr); - this.log("superfunction", "Created on: " + sys_created_on); - } -return arr; -}, - -/** - * Description: This is a very important method... - * Parameters: None. - * Returns: Logs a very important message. - */ - -superFunction2: function(){ - for (var i = 1; i <= 100000; i++) { - this.log("superFunction2", "ILOVEEARL); - } - } -}, - type: 'super_utils' -}); - -Calling Script Include Via Server Side Script: -var utils = new scope.super_utils('true', 'superFunction2'); \ No newline at end of file diff --git a/Server-Side Components/Script Includes/Clean Framework/README.md b/Server-Side Components/Script Includes/Clean Framework/README.md deleted file mode 100644 index a626718452..0000000000 --- a/Server-Side Components/Script Includes/Clean Framework/README.md +++ /dev/null @@ -1 +0,0 @@ -This is a generally useful framework for script includes that in use in my day to day work as well as personal projects on my PDI. It allows you to easily enable logs when calling whichever method you want to use when developing and debugging, then easily disable them by no longer passing in the initilization debug true param or setting it to false in your call. It's very sleek and I highly recommend using it wherever you can to help keep a clean codebase. I also included some examples of how I docment each of my methods. I find it to be helpful when dealing with complex methods I haven't touched in awhile as well as making it easy for new developers to look at the code and hit the ground running quickly. \ No newline at end of file From f1d1a1e8f8e442a016044f3b90cab884cb7db701 Mon Sep 17 00:00:00 2001 From: Greg <67873454+1shabby@users.noreply.github.com> Date: Thu, 9 Oct 2025 23:12:05 -0500 Subject: [PATCH 3/3] Added a Log Utils to the Script Includes Directory --- .../Script Includes/Log Utils/Code.js | 31 ++++++++++ .../Script Includes/Log Utils/README.md | 56 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 Server-Side Components/Script Includes/Log Utils/Code.js create mode 100644 Server-Side Components/Script Includes/Log Utils/README.md diff --git a/Server-Side Components/Script Includes/Log Utils/Code.js b/Server-Side Components/Script Includes/Log Utils/Code.js new file mode 100644 index 0000000000..536d8a49ac --- /dev/null +++ b/Server-Side Components/Script Includes/Log Utils/Code.js @@ -0,0 +1,31 @@ +var log_utils = Class.create(); +log_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { + initialize: function(debug, noDebugMethods) { + this.debug = false; // Flag to allow debug or not on this script include + this.noDebugMethods = []; // Array of methods to not log from + + if (debug) { + this.debug = debug; + } + + if (noDebugMethods) { + this.noDebugMethods = noDebugMethods.split(','); + } + + // Global Variables For Use In Script + + }, + + /** + * Description: Takes in a method name and message and logs the message in gs.info if debug and method isn't in noDebugMethods + * Parameters: [string] - methodName: name of method calling log. + [string] - msg: message being called in log. + * Returns: None. + */ + + log: function(methodName, msg) { + if (this.debug && this.noDebugMethods.indexOf(methodName) === -1) { + gs.debug('[Log Utils - ' + methodName + '] ' + msg); + } + }, + diff --git a/Server-Side Components/Script Includes/Log Utils/README.md b/Server-Side Components/Script Includes/Log Utils/README.md new file mode 100644 index 0000000000..4bef1abfad --- /dev/null +++ b/Server-Side Components/Script Includes/Log Utils/README.md @@ -0,0 +1,56 @@ +This is a lightweight utility for managing logging within Script Includes. +It provides a simple, configurable way to enable or disable debug logs during development and to exclude specific methods from logging when necessary. + +This approach helps maintain clean logs, reduces noise during debugging, and allows for quick toggling of logging behavior once development is complete. + +Usage: +You can call the log method anywhere inside your Script Include to record a log message: +this.log(, ); + +Example: +this.log('processData', 'Starting data processing...'); + +Initialization Parameters: +Logging behavior is controlled through the parameters passed to the initialize method when creating the Script Include instance. + +var utils = new scope.utils(true, 'methodName1,methodName2'); + +Parameters: +====================================================================================================================== +|debug | Boolean false | Enables or disables logging. Set to true to allow logs, false to suppress them. | +|noDebugMethods | String "" | A comma-separated list of method names that should not produce logs. | +====================================================================================================================== + +Example Use Case: +If you’re developing a new method that depends on existing, stable methods, you can temporarily disable logging for the known-good methods. +For example: + +var utils = new scope.utils(true, 'validatedMethod'); + +This enables logs for all methods except validatedMethod, keeping your system logs focused on what you’re currently debugging. + +When development is complete, you can remove the parameters (or set debug to false) to disable all logs. + +Notes: +The script uses gs.debug() for logging to keep logs easily filterable within the system logs. +You can switch to gs.info(), gs.warn(), or gs.error() depending on your needs. + +Logging should typically remain disabled (debug = false) in production to avoid unnecessary system overhead. + +This utility is flexible and can be dropped into almost any Script Include with minimal setup. + +Example in Context: + +var example_utils = Class.create(); +example_utils.prototype = Object.extendsObject(global.AbstractAjaxProcessor, { + initialize: function(debug, noDebugMethods) { + this.logger = new log_utils(debug, noDebugMethods); + }, + + processData: function() { + this.logger.log('processData', 'Starting process...'); + // ...your logic here... + this.logger.log('processData', 'Process completed successfully.'); + } +}); +