Welcome to the DevTools - created and maintained by Sascha Wildgrube.
DevTools contains a number of script includes with useful javascript functions and classes like a GetType() function that really works. A few UI improvements like the Re-Test button in the test result form and shortcuts to various - sometimes hidden - views and system properties in your instance.
DevTools is NOT an officially supported ServiceNow product.
DevTools does NOT come with any kind of warranty. If you use it, you own it!
Some features contained on DevTools and the techniques being used might be considered as a violation of security policies. Please make sure any use is based on conscious choice and careful assessment. This specifically applies to the functions RunScriptInScope() and RunScriptInGlobalScope().
x_snc_devtools.AppInstall();
var testdata = new x_snc_devtools.TestDataAPI('_ATF_DEVTOOLS_'); gs.info('Before DeleteAllData(): '+x_snc_devtools.RenderValue(testdata.GetAllData())); testdata.DeleteAllData(testdata.GetAllData()); gs.info('After DeleteAllData(): '+x_snc_devtools.RenderValue(testdata.GetAllData()));
DevTools can help to format (float) numbers in forms, related lists and list views in the classic UI. Follow these steps to activate the feature:
function DevToolsGetFormatConfig(grRecord) { var strTable = grRecord.getRecordClassName(); if (strTable == 'your_table') { var formatconfig = { your_field: { decimals: 2, postfix: ' %' } }; return formatconfig; } return false; }
DevTools allows you to deactivate specific Service Portals.
A new field "Active" is added to the sp_portal table. Once set to false, the corresponding Service Portal will just disappear and is no longer accessible.
Controls if the Debug() function should write to the system log.
Controls if debug output should contain the current transaction runtime in milliseconds.
Specify DevTools log level. Valid choices are error, warn, info and debug.
Controls if the "Delete Update Set" button should be visible.
Controls if the "Find Sys ID" button should be visible.
Controls if the field formatting feature is active or not. If it is, in classic UI forms, related lists, and list views, read-only fields are being formatted according to rules specified by a function implemented via the DevTools extension point.
Controls if the "List" button should be globally visible.
Controls if the "Save" button should be globally visible.
Controls if the "Up" button should be visible for supported tables.
Controls if the "What Runs" button should be visible.
Adds a test to a suite
Create a syntax editor macro to access the function or class defined in the script include.
Delete this update set. Available to admin users only.
Execute a scheduled job on demand and stay on the current form. This UI Action replaces the OOTB Execute Now UI Action.
Asks the user for a sys id and if the record exists, navigates to the record's form page. Available to admin users only.
The "List" button navigates from a record's form view to it's list view.
Run an ATF test directly from any screen that has a reference to a test.
Global Save button
The "Up" button navigates to the record's parent record (if possibe).
Opens the whatruns page to display an analysis on what runs on the table for the different CRUD operations.
AppBuilder adds various application files to a scoped app.
Add an ATF test to an existing test suite.
Retrieves information about the app's dependencies to other apps and required versions.
Gets a DevTools system property.
This script installs DevTools
Performs a number of changes to a scoped app's assets to maintain application sanity. E.g., the function removes the copied_from attribute in atf tests, removes unneccesary field level ACLs and removes the is_private flag from system properties.
Sets a DevTools system property.
Appends the second given array to the first.
Adds a value to an arry if it doesn't exist yet. Returns the resulting array.
Removes a value from an array.
Returns an array with unique values only.
Checks if a value exists in an array and returns true in that case, otherwise false.
Returns the operation (of a business rule) based on the provided record.
Creates a copy of the given value.
Create a PDF file based on html and attaches the created file as an attachment to the given record.
Creates the raw data for a QRCode based on a given input string.
The result is provided as an array of rows containing arrays of boolean values for each column.
Converts a monetary amount from one currency to another.
Creates a new database index if it doesn't exist yet. Warning, there is no way to undo that operation!
Produce a debug log output but only if x_snc_devtools.debug.log is set to true.
The DevToolsClientAPI is a client callable proxy for ajax calls to some of the functions provided by DevTools.
The DocumentationAPI helps to render fragments of an HTML page that documents the components of a scoped application.
Returns the name of a scoped application (and removes any "work in progress" postfixes).
Get an application record based on sys_id or scope name.
Returns the scope name of a scoped application.
Returns an array no matter what input type is given and performs necessary conversion if another type is provided.
Returns either true or false no matter what kind of value is given.
Get a country record based on sys_id, name or ISO3 code.
Returns the database views which use a given table.
Returns the current date as a string in UTC.
Returns a float value.
Retrieves formatting information for the fields of the given records.
Returns all groups of a given user. An additional filter can be applied to the groups to be returned.
Generate a hexadecimal SHA 256 hash string.
Returns the URL path of a table's list in the instance.
Returns the URL path of a specific record in the instance.
Returns the URL path of a specific record in the instance.
Returns the URL of a specific record in the instance.
Returns the instance root URL.
Returns an integer value.
Returns all key names of an object in an array. Returns an empty array if no object is provided or no members exist.
Returns the DevTools link directory with many useful links for admins and developers.
Returns the version of a package if it exists, otherwise false.
Get the parent record of a given record if it is possible.
Returns the parent table of the given table. False if the given table does not exist or is not derived from another table.
Gets a system property independent of its scope.
Get a pseudo-random string token of a given length consisting of numbers only.
Shorthand to get a record from a table based on a sys_id. If the bNoCrossScope parameter is set to true, GetRecord will not attempt to load the record from the global scope if it cannot load it from within the application scope.
Returns the sys_id of the record that has been created or found in the given test step.
Returns an array with the names the active roles of a user.
Returns an array with the sys_ids of the active roles of a user.
Returns a string that represents a version of the input string that does not exceed the specified length. The last characters are replaced by a hash-based alpha-numeric postfix to avoid string collisions.
Returns a string value in all cases. Arrays and objects are converted into comma separated strings.
Returns all tables which have at least one column with the given type.
Returns the number of millisenconds passed since the start of the unix epoch.
Returns the number of millisenconds passed since the start of this transaction.
Returns the type of a value.
Get a user record based on sys_id, user_name, name or email address.
Returns the value of an object that is (or is not) part of an recursive object without generating errors if the object does not exist.
Executes the delete member function of a glide record in global scope.
Executes the deletemultiple member function of a glide record in global scope.
Executes the insert member function of a glide record in global scope.
Executes the query member function of a glide record in global scope.
Executes the setValue member function of a glide record in global scope.
Executes the setValue member function of a glide record in global scope for all values provided in the given object.
Executes the update member function of a glide record in global scope. If bGhost is set to true, the record update will not trigger any system field updates or workflows.
Converts a string to html.
Renders an HTML link.
Renders a link directory with based on a given linkdirectory object.
Renders html elements that exactly reflect a DIN A4 page to support PDF rendering.
Renders a black and white QC code image based on the given payload string as plain vanilla html.
Renders any value using RenderValue() into an html document.
Renders a the outcome of the WhatRuns() function for the given tables.
Performs a single synchronous http request.
A class representing an image which can be used to generate BMP files or html output.
The InstallerAPI class supports scripted installation steps as part of the installation of a scoped app.
Returns true if the given value is an array. False if not.
Returns true if domain separtion is installed on the instance. Keep in mind, domain separation may or may not be active.
Checks if two values are equal. The function also supports arrays and can ignore the order of array elements while comparing.
Checks if the given record is really a GlideRecord object representing an existing record.
Returns true if the given value is an object. False if not.
Returns true if the given parameter is the name or the sys_id of an existing system property. False if not.
Checks if a table is fully cross-scope accessible. The function returns true if the access is set to public and apps from other scopes are allowed to perform read, create, update and delete operations.
Returns true if domain separation is supported and active on a given table, false if not.
If the given user is a "technical" user, the function returns true, otherwise false.
Returns true if the user is an admin user, false if not.
Returns true of the current user has the provided role explicitly. Returns true if that is the case, returns false if not. If an admin does not explicitly have that role, it will also return false.
Returns true if the current user is elevated to security_admin, false if not.
Returns true of the given table column exists. False if not.
Returns true of the given string identifies a database view. False if not.
Returns true of the given value is a valid function. False if not.
Checks if the given record is a valid glide record object. Returns true if it is, false if not.
Checks if the given string is a syntactically correct sys_id. Returns true if it is, false if not.
Returns true of the given table exists. False if not.
Returns true if the given string is a valid version number, false if not.
Checks if the first version is compatible to the second version - whereas the first version is the version of an installed application and the second version is a requirement.
Loads all local test messages for an "application".
Produces a log output
Merges two objects or arrays.
Parses a csv formatted string into an array of objects representing each row.
Parses a string and returns a time value.
Parses a string and returns an object or false in case of failure (instead of pointlessly throwing an exception).
Parses a URL and returns its components as an object.
Parses a the URL parameters and returns the parameters as an object.
Measure the average performance of a query in milliseconds from the perspective of a given user based on a defined number of repetitions.
The result is returned as a JSON object.
Measure the average performance of a number of queries in milliseconds from the perspective of a number of given users based on a defined number of repetitions.
The result is returned as a JSON object.
Adds an attachment to a record.
Delets all attachments of a given record.
Delets all attachments of a given record that match a given the file name.
A function to process large amounts of records using a callback function. The function makes use of a specified date/time field to determine which record to process next. Multiple instances of a background script can run using this function to work on large amounts of records in a table without interfering with each other.
For large tables it is imperative to add an index on the date time field!
If the ghost parameter is set to true, records are updated with setWorkflow(false) to avoid business rules etc. being triggered.
Deletes a single record from a table. Returns true if the record could be deleted successfully.
Shorthand to get a single value from a record from a table based on its sys_id.
Inserts a new record into a table with the specified values if the columns exist.
Queries records based on the given values or based on an encoded query. The function will return a record if exactly one record is found, otherwise false.
Queries an existing record based on query values or inserts a new record into a table with the specified values if the record does not exist. The bUpdate parameter controls if the existing record should be updated with the given values or not.
Sets a single field value on a given record. If bGhost is set to true, no business rules are executed as a result of the update.
Redirects to the form view of the given record if it is valid.
Returns a user-friendly number of bytes using KB, MB and GB where appropriate.
Renders the given date as an UTC iso string.
Renders a date/time value as an UTC ISO string.
Renders the given date/time according to the current user's preferences.
Renders a string with a technical summary of a record including its table name, sys_id, number if available and other text data that can help to identify the record while debugging.
Renders the given time as an UTC iso string.
Render any value as a string. In case of objects, the keys are displayed in alphabetical order. In case of arrays, the elements are displayed in the given order. In case of a GlideRecord, the table name, sys_id and number (if available) are displayed on top, and a selected choice of fields leads the list of values despite the alphabetical order.
Render a value as a hexadecimal string.
Run any script in the global scope even if the context is a scoped application. Note that the script will be placed into a function body so you cannot assume that declared local variables will be valid after its execution. To return a value from the script, set the "result" variable.
WARNING: Using this function might be considered as a violation of security policies.
Please make sure any use is based on conscious choice and careful assessment.
Runs any script in any scope even if the context is a scoped application. Note that the script will be placed into a function body so you cannot assume that declared local variables will be valid after its execution. To return a value from the script, set the "result" variable.
WARNING: Using this function might be considered as a violation of security policies.
Please make sure any use is based on conscious choice and careful assessment.
Sets a system property independent of its scope.
Sets a value to an object that is (or is not yet) part of an recursive object without generating errors if the object does not exist yet.
Sleeps for the given amount of seconds. This function serves as an alternative to gs.sleep() which is not supported in scoped apps.
The StopWatch class measures time in the same way as a real stopwatch does.
Checks a given string against a regular expression.
Equivalent of the JavaScript method padStart.
The function returns the input string with all characters removed that are contained in the blacklist string.
Replaces all occurences of a string by another string in a string.
Sets an attribute of a table to a given value.
The TestAPI class supports scripted tests.
A class to create test data records.
Adds (or substracts) a given number of days to (or from) a given time value (in milliseconds).
A class to manage the transaction cache.
Deletes an update set including all its files.
Adds a role to a user if the user doesn't have the role already.
Impersonates a user based on a user's sys id.
Identifies business rules that run for the given tables in the different CRUD operations.
Appends the second given array to the first.
Adds a value to an arry if it doesn't exist yet. Returns the resulting array.
Returns an array with unique values only.
Checks if a value exists in an array and returns true in that case, otherwise false.
Creates a copy of the given value.
Produces a debug output.
Formats all fields on the page: in the form, related lists or a list view according to the format configuration provided by the backend.
Renders a value based on a given configuration.
Returns an array no matter what input type is given and performs necessary conversion if another type is provided.
Retrieves the format config using an ajax request and caches the response to avoid duplicate requests.
Retrieves the format config for multiple records using an ajax request.
Returns an integer value.
Returns all key names of an object in an array. Returns an empty array if no object is provided or no members exist.
Returns a string value in all cases. Arrays and objects are converted into comma separated strings.
Returns the type of a value.
Returns the value of an object that is (or is not) part of an recursive object without generating errors if the object does not exist.
Identifies all records that are displayed on the current page by iterating over various html elements.
Called when a page is loaded to invoke DevTools features.
Returns true if the given value is an array. False if not.
Checks if two values are equal. The function also supports arrays and can ignore the order of array elements while comparing.
Returns true if the given value is an object. False if not.
Checks if the given string is a syntactically correct sys_id. Returns true if it is, false if not.
Produces a log output.
Merges two objects or arrays.
Attaches a listening callback functon to a DOM element.
Parses a string and returns an object or false in case of failure (instead of pointlessly throwing an exception).
Performs an ajax request (either synchronous or asynchronous) to a defined API and function.
Sets a value to an object that is (or is not yet) part of an recursive object without generating errors if the object does not exist yet.
DevTools contains the following customized test step configurations:
Checks if another required scoped application is installed in a supported version.
Performs a sanity check on a scoped app. E.g. it checks if all contained system properties are not set private and all tests have an empty copied_from field.
Checks if the given table is configured for full cross scope access.
Checks if there are remainders of test data from previous tests based on a given test data prefix.
The DevTools extension point allows to extend some DevTools features.
var DevTools = Class.create(); DevTools.prototype = { initialize: function() { }, GetParentRecord: function(grRecord) { var IsValidFunction = x_snc_devtools.IsValidFunction; if (IsValidFunction(x_this_app_scope.DevToolsGetParentRecord)) { return DevToolsGetParentRecord(grRecord); } return false; }, GetLinkDirectory: function(linkdirectory) { var IsValidFunction = x_snc_devtools.IsValidFunction; if (IsValidFunction(x_this_app_scope.DevToolsGetLinkDirectory)) { return DevToolsGetLinkDirectory(linkdirectory); } return linkdirectory; }, GetFormatConfig: function(grRecord) { var IsValidFunction = x_snc_devtools.IsValidFunction; if (IsValidFunction(x_this_app_scope.DevToolsGetFormatConfig)) { return DevToolsGetFormatConfig(grRecord); } return false; }, type: 'DevTools' };
Copyright 2020-2022 by Sascha Wildgrube
Licensed under the Apache License, Version 2.0 (the "License")
You may not use DevTools except in compliance with the License.
You may obtain a copy of the License at: https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
var grRecord = new GlideRecord('sys_db_object'); grRecord.addQuery('name','=','sys_script_include'); grRecord.query(); if (grRecord.next()) { grRecord.access = ''; grRecord.read_access = 'true'; grRecord.create_access = 'false'; grRecord.update_access = 'false'; grRecord.delete_access = 'false'; grRecord.update(); } gs.invalidateCache();
First baselined version