Skip to content

Clean Script Include Framework#1939

Closed
1shabby wants to merge 1 commit intoServiceNowDevProgram:mainfrom
1shabby:Script-Include-Framework
Closed

Clean Script Include Framework#1939
1shabby wants to merge 1 commit intoServiceNowDevProgram:mainfrom
1shabby:Script-Include-Framework

Conversation

@1shabby
Copy link
Contributor

@1shabby 1shabby commented Oct 8, 2025

PR Description:

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.

Pull Request Checklist

Overview

  • Put an x inside of the square brackets to check each item.
  • I have read and understood the CONTRIBUTING.md guidelines
  • My pull request has a descriptive title that accurately reflects the changes and the description has been filled in above.
  • I've included only files relevant to the changes described in the PR title and description
  • I've created a new branch in my forked repository for this contribution

Code Quality

  • My code is relevant to ServiceNow developers
  • My code snippets expand meaningfully on official ServiceNow documentation (if applicable)
  • I've disclosed use of ES2021 features (if applicable)
  • I've tested my code snippets in a ServiceNow environment (where possible)

Repository Structure Compliance

  • I've placed my code snippet(s) in one of the required top-level categories:
    • Core ServiceNow APIs/
    • Server-Side Components/
    • Client-Side Components/
    • Modern Development/
    • Integration/
    • Specialized Areas/
  • I've used appropriate sub-categories within the top-level categories
  • Each code snippet has its own folder with a descriptive name

Documentation

  • I've included a README.md file for each code snippet
  • The README.md includes:
    • Description of the code snippet functionality
    • Usage instructions or examples
    • Any prerequisites or dependencies
    • (Optional) Screenshots or diagrams if helpful

Restrictions

  • My PR does not include XML exports of ServiceNow records
  • My PR does not contain sensitive information (passwords, API keys, tokens)
  • My PR does not include changes that fall outside the described scope

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.
@WillemZeiler WillemZeiler self-assigned this Oct 8, 2025
Copy link
Contributor

@WillemZeiler WillemZeiler left a comment

Choose a reason for hiding this comment

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

Thank you for your submission. Enjoyed going through it, especially the last function haha! However, the name of the script is not reflecting the content, perhaps change it for a more descriptive name. I have added some comments to the code, please see if you can make the requested changes. Closing this PR for now.

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


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.


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.

Log misses a " at the end (after ILOVEEARL)

},

/**
* 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?


// Global Variables For Use In Script
this.CASETYPE1 = '[casetype 1 table]';
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?

}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants