Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions Server-Side Components/Script Includes/Clean Framework/Code.js
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]';
Copy link
Contributor

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?

this.CASETYPE2 = '[casetype 2 table]';
Copy link
Contributor

Choose a reason for hiding this comment

The 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"
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

10.000 that is a lot of love for Earl!
Probably best to make it clear that this is not ment to use in production... it might surprise you what people copy paste from the internet.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Loading