-
Notifications
You must be signed in to change notification settings - Fork 917
Clean Script Include Framework #1939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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]'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This does not seem to be used in the 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.info('[Super_Utils - ' + methodName + '] ' + msg); | ||
| } | ||
| }, | ||
|
|
||
| /** | ||
| * Description: Takes in an input then gets all records where field is input and created by is "iloveearl" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate a bit more how this wrapper function is helpful? What does it solve? |
||
| * 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10.000 that is a lot of love for Earl!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Log misses a " at the end (after ILOVEEARL) |
||
| } | ||
| } | ||
| }, | ||
| type: 'super_utils' | ||
| }); | ||
|
|
||
| Calling Script Include Via Server Side Script: | ||
| var utils = new scope.super_utils('true', 'superFunction2'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the readme I would also expect notes for each function. Can you add this per function? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what people need to set here and why?