Function: TableCheck(config)
Creates a table check that scans records in a specific table (scan_table_check).
Supports three modes:
- Condition-only: use
conditionsto filter records (default) - Script-only: set
advanced: trueand provide ascript - Combined: set
advanced: truewith bothconditionsandscript
Usage
// Condition-based check
TableCheck({
$id: Now.ID['check-inactive-users'],
name: 'Inactive Users with Roles',
active: true,
category: 'security',
priority: '2',
shortDescription: 'Finds inactive users that still have active roles',
table: 'sys_user',
conditions: 'active=false^roles!=',
})
// Advanced script-based check
TableCheck({
$id: Now.ID['check-large-attachments'],
name: 'Large Attachment Detector',
active: true,
category: 'performance',
priority: '3',
shortDescription: 'Identifies records with oversized attachments',
table: 'sys_attachment',
advanced: true,
script: Now.include('./check-large-attachments.js'),
})
// Combined conditions and script check
TableCheck({
$id: Now.ID['check-stale-incidents'],
name: 'Stale Incident Detector',
active: true,
category: 'manageability',
priority: '2',
shortDescription: 'Finds incidents that are open and stale',
table: 'incident',
advanced: true,
conditions: 'state!=6^state!=7',
script: Now.include('./check-stale-incidents.js'),
})
Parameters
config
TableCheck<keyof Tables>
Properties:
-
$id (required):
string | number | ExplicitKey<string> -
category (required):
ScanCategoryClassifies what aspect of the instance this check evaluates -
name (required):
stringUnique name identifying this check -
priority (required):
ScanPrioritySeverity level: 1=Critical, 2=High, 3=Moderate, 4=Low -
shortDescription (required):
stringBrief summary displayed in scan results -
table (required):
keyof TablesTable to scan -
active (optional):
booleanControls whether this check runs during scans. Defaults to true -
advanced (optional):
booleanEnables custom script mode instead of condition-based scanning -
conditions (optional):
stringEncoded query filtering which records to evaluate -
description (optional):
stringFull explanation of what this check evaluates and why -
documentationUrl (optional):
stringLink to external documentation for this check -
findingType (optional):
unknownTable where findings are stored. Defaults to scan_finding -
resolutionDetails (optional):
stringGuidance on how to remediate findings from this check -
runCondition (optional):
stringEncoded query condition that must be met before this check runs -
scoreMax (optional):
numberMaximum number of findings for scoring calculation -
scoreMin (optional):
numberMinimum number of findings before scoring applies -
scoreScale (optional):
numberMultiplier applied to the finding count for scoring -
script (optional):
stringServer-side script executed when the check runs -
useManifest (optional):
booleanUses the upgrade manifest to scope findings to changed records
Examples
Basic Table Check
Create instance scan checks that scan records in specific tables using conditions or advanced scripts
/**
* @title Basic Table Check
* @description Create instance scan checks that scan records in specific tables using conditions or advanced scripts
*/
import { TableCheck } from '@servicenow/sdk/core'
export const inactiveUsersWithRoles = TableCheck({
$id: Now.ID['check-inactive-users-roles'],
name: 'Inactive Users with Roles',
active: true,
category: 'security',
priority: '2',
shortDescription: 'Finds inactive users that still have active role assignments',
table: 'sys_user',
conditions: 'active=false^roles!=',
description:
'Identifies user accounts that have been deactivated but still retain role assignments, which may pose a security risk if the accounts are reactivated.',
resolutionDetails:
'Remove role assignments from inactive user accounts or confirm the roles are intentionally retained for reactivation.',
})
export const largeAttachmentCheck = TableCheck({
$id: Now.ID['check-large-attachments'],
name: 'Large Attachment Detector',
active: true,
category: 'performance',
priority: '3',
shortDescription: 'Identifies records with oversized attachments that impact performance',
table: 'sys_attachment',
advanced: true,
script: Now.include('./check-large-attachments.js'),
useManifest: true,
})
export const staleIncidentCheck = TableCheck({
$id: Now.ID['check-stale-incidents'],
name: 'Stale Incident Detector',
active: true,
category: 'manageability',
priority: '2',
shortDescription: 'Finds incidents that are open and stale',
table: 'incident',
advanced: true,
conditions: 'state!=6^state!=7',
script: Now.include('./check-stale-incidents.js'),
})
check-large-attachments.js
;(function checkLargeAttachments(current) {
if (current.size_bytes > 10485760) {
finding.increment()
}
})(current)
check-stale-incidents.js
;(function checkStaleIncidents(current) {
var lastUpdated = new GlideDateTime(current.sys_updated_on)
var now = new GlideDateTime()
var diff = GlideDateTime.subtract(lastUpdated, now)
if (diff.getNumericValue() > 7776000000) {
finding.increment()
}
})(current)