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