logo

NJP

Instance Scan "Data" Scan Check examples

Import · Nov 02, 2021 · article

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

Hi there,

When talking about Instance Scan, mostly mentioned for setting up Scan Checks is about performing checks on code, certain settings on Business Rules / Client Scripts / Script Includes, etcetera. Though why limit ourselves to only best practices on the coding front? Instance Scan has a really powerful scan engine, with which you can interrogate your instance on way more.

Data

In this article I'll share some examples of Scan Checks which you could use for a "Data" suite. Data checks which you could perform regularly on a Production instance. For example weekly, to support the activities of a System Administrator. Obviously these checks can bring data issues to the surface which need to be corrected, though the question could also be why are those data issues occurring? Maybe there's some scripting issue or integration issue going on, or a System Administrator who incorrectly performed some manual actions, etcetera.

Data examples

Table Check: Active approval for inactive task

Category

Manageability

Description

Approvals for inactive tasks indicate a process error or a technical error. Tasks should not proceed when approvals are still open or only canceled. If canceled, active approvals should be too.

Table

sysapproval_approver

Condition

sysapproval.active=falsestateINnot requested,requested

Table Check: Active Notifications with inactive recipient Users

Category

Manageability

Description

Validate that all notifications are configured with active users if there are any defined under the "Users" field.

Documentation

https://docs.servicenow.com/csh?topicname=t%5FCreateANotification.html&version=latest

Table

sysevent_email_action

Condition

active=truerecipient_usersISNOTEMPTY

Script

(function (engine) {

    // Define variables
    var regex = /[0-9a-f]{32}/g;
    var recipients = engine.current.recipient_users.split(',');

    var l = recipients.length;
    for(var i = 0; i < l; i++) {
        if(recipients[i].match(regex)) {
            var getUser = new GlideRecord('sys_user');
            getUser.addQuery('sys_id', recipients[i]);
            getUser.addQuery('active', false);
            getUser.setLimit(1);
            getUser._query();

            // Create scan finding
            if(getUser.hasNext()) {
                engine.finding.increment();
                return;
            }
        }
    }

})(engine);

Table Check: Active Users with inactive Manager

Category

Manageability

Description

Validate that all users are configured with an active user if there is any defined under the "Managers" field.

Documentation

https://docs.servicenow.com/csh?topicname=c%5FUserAdministration.html&version=latest

Table

sys_user

Condition

active=truemanager.active=false

Table Check: Active Workflow Context with Inactive Parent

Category

Manageability

Description

Workflows are generally run during the lifecycle of a record. When the record reaches a closed state, the Workflow should be finished. Still running Workflows might indicate an issue in your environment, for example the Workflow itself, related scripting, etc..

Table

wf_context

Condition

active=true

Script

(function (engine) {

    // Query record 
    var getRecord = new GlideRecord(engine.current.getValue('table'));
    getRecord.addQuery('sys_id', engine.current.getValue('id'));
    getRecord.addQuery('active', false);
    getRecord.setLimit(1);
    getRecord._query();

    // Create scan finding
    if(getRecord._next()) {
        engine.finding.increment();
    }

})(engine);

Table Check: Orphan Incident Tasks

Category

Manageability

Description

Incident Tasks that are not associated with an Incident will most likely never be seen and modified. Every Incident Task should have a parent Incident as they always should be a part of an Incident.

Table

incident_task

Condition

active=trueincidentISEMPTY

GitHub example-instancescan-checks

The example Linter Checks mentioned in this article can also be found on the "example-instancescan-checks" GitHub repository. Also other Scan Checks can be found there which have been contributed by several people.

---

And that's it actually. Hope you like it. If any questions or remarks, let me know!

Kind regards,

Mar k Roethof

ServiceNow Technical Platform Architect @ Quint Technology

2x ServiceNow Developer MVP

2x ServiceNow Community MVP

---

View original source

https://www.servicenow.com/community/developer-articles/instance-scan-quot-data-quot-scan-check-examples/ta-p/2297963