Naming pattern validation
Summarize
Summary of Naming pattern validation
The TNI Naming Application in ServiceNow validates naming patterns at two independent stages to ensure accurate and conflict-free names within inventory templates:
Show less
- Save-time validation: Validates individual naming patterns when you create or edit them.
- Overview-render validation: Validates resolved names across related templates during the rendering of the Inventory Template Overview tab.
Save-time validation
When defining or editing a naming pattern in the Define name pattern modal, the system performs immediate validation before applying the pattern:
- Valid pattern: Displays a green confirmation message with a sample resolved name preview, and enables the Apply button.
- Invalid or empty pattern: Shows a red error message indicating the pattern produces an empty or invalid name. This blocks applying the pattern.
The pattern is only saved to the record after clicking Apply on a valid pattern and saving the record. Closing the modal or record without saving discards changes.
Overview-render validation
When the Inventory Template Overview tab renders the hierarchy, validation providers check resolved names among sibling templates under the same parent. The default validation provider flags duplicate names among siblings (e.g., two slots resolving to the same name).
Key points include:
- Validation occurs one tree level at a time among sibling templates.
- Duplicate-name checks do not compare names across different hierarchy branches.
- Administrators can extend or replace default validation by registering custom validation providers.
Combining multiple validation rules
If multiple validation rules flag the same template, the Overview tab aggregates their messages:
- The Validation failed banner concatenates error descriptions from all providers, separated by semicolons.
- The tree's error badge displays a single label, set by the last provider that flagged the template.
For example, a template failing both custom and duplicate-name checks will show both errors in the banner but only one badge label.
Handling unresolvable variables
When a pattern references variables not applicable in a template's context (e.g., a top-level slot referencing a parent slot variable), the unresolved variable is displayed as a ? in the resolved name on the tree node label.
- This substitution serves as a visual indicator of context mismatch but does not trigger an error badge or validation failure.
- It helps identify patterns that use variables incompatible with certain hierarchy positions without blocking the rendering.
Practical benefits for ServiceNow customers
- Ensures naming patterns are syntactically correct and produce meaningful names before saving.
- Prevents duplicate names among sibling inventory template elements, reducing conflicts and confusion.
- Provides clear feedback on naming issues at both pattern creation and hierarchy rendering stages.
- Allows customization of validation rules to fit unique business requirements.
- Displays unresolved variables clearly to aid troubleshooting without causing validation failures.
The TNI Naming Application validates naming patterns at two distinct moments — once when you save a pattern, and again when the Inventory Template Overview tab renders the resolved hierarchy.
Two validation moments
The two moments are independent. A pattern that passes save-time validation can still produce results that fail Overview-render validation, because Overview-render checks compare patterns across multiple related templates, while save-time checks evaluate one pattern at a time.
Save-time validation
When you author or edit a pattern in the Define name pattern modal, the modal validates the pattern before letting you apply it. Two outcomes are visible in the modal:
-
Pattern accepted. A green message appears beneath the input: Valid name pattern. Preview: <resolved name>. The resolved name in the preview is a sample evaluation. The Apply button is enabled.
-
Pattern invalid or produces an empty result. A red message appears: Name pattern results in empty name. Please try again. The Apply action is blocked. The same message appears whether the pattern has invalid JavaScript, references a variable that doesn't exist, or produces an empty string when evaluated.
The pattern is committed to the record only when you click Apply on a valid pattern and then save the underlying record. If you close the modal or close the record without saving, the pattern is not persisted.
Overview-render validation
When the Inventory Template Overview tab evaluates the hierarchy, registered validation providers run against the resolved names of related templates. Each provider examines the related templates at one tree level at a time — the siblings under a single parent — and writes validation results back to any related template that fails its rule.
A single validation provider ships with the application by default: a duplicate-name check
that flags two or more siblings whose patterns resolve to the same name. For example, if two
slots at the same level both resolve to Slot -5, both slots are flagged.
The check is scoped to direct siblings of the same parent — it does not compare a slot's
name against a sub-slot's name in a different branch.
Customer administrators can extend, augment, or replace this default check by registering additional validation providers. For more information, see Extension point for custom naming validation.
How multiple validation rules combine
When multiple validation rules flag the same related template, the Overview tab combines their outputs:
-
The Validation failed banner concatenates the error descriptions from all providers that flagged the related template, separated by
;(semicolon and space). All errors are visible in one banner. -
The Error badge on the tree shows only one label. When multiple providers each write a badge label, the badge displayed on the node is set by the last provider to flag the related template.
Example: a related template that fails both a custom check and the default duplicate-name check shows this banner:
Validation failed: This is a slot fake error: Slot -4; Duplicate name at same level: Slot -4
Unresolvable variables in resolved names
Patterns can reference variables that have no value in a particular related template's
context. For example, a top-level slot directly under an equipment template has no parent
slot, so the variable parent_slot_name cannot be resolved for it.
When the Inventory Template Overview encounters an unresolvable variable, it substitutes
? for the variable in the resolved name on the tree node label. The
? substitution is a signal that the pattern is using variables that do
not fit the related template's position in the hierarchy.
? substitution does not raise an
Error badge or a Validation failed banner.
It is a display-only indicator in the tree node label.