What It Does
The getControl() method returns the raw DOM HTMLElement that represents the field's input control. This is the actual <input>, <select>, or <textarea> element that users interact with, not the container div or label elements around it.
Internally, ServiceNow maintains a mapping between field names and their DOM elements. When you call getControl(), it looks up the field in this registry and returns the associated input element. The method traverses the form's DOM structure to locate the specific control element, filtering out wrapper divs and decorative elements.
The method returns null when the field doesn't exist on the form, when the field exists but isn't currently rendered (like fields hidden by UI policies), or when the field is read-only and ServiceNow renders it as plain text instead of an input control. Dictionary fields that don't appear on the form will also return null.
Different field types return different element types. String and number fields return <input> elements, choice fields return <select> elements, and long text fields return <textarea> elements. Reference fields are complex because they include both a display input and a hidden input for the sys_id—getControl() returns the display input that users type into.
This method is closely related to getSectionNames() and getSections() in that they all provide DOM access, but getControl() is field-specific. Unlike getValue() and setValue() which work with field values, this method gives you the presentation layer.
When to Use This
Use getControl() when you need to manipulate DOM attributes, CSS classes, or event listeners that aren't available through standard GlideForm methods. Common scenarios include adding custom validation styling, implementing complex keyboard shortcuts, or integrating third-party JavaScript libraries that require direct DOM access. You might also need it for accessibility modifications like custom ARIA attributes.
Prefer standard GlideForm methods whenever possible. Use setValue() and getValue() for field values, setReadonly() for making fields non-editable, and setVisible() for showing and hiding fields. These methods are upgrade-safe and work consistently across different UI frameworks.
Avoid using getControl() for basic field operations. DOM manipulation breaks when ServiceNow updates the UI framework, and your code won't work in mobile or Service Portal.
Return Value
Returns an HTMLElement object when successful, or null when the field isn't found or isn't rendered as an interactive control. The returned element has all standard DOM properties and methods—value, className, addEventListener(), and others.
Always check for null before using the returned element, especially in UI policies where field visibility can change. The element reference remains valid as long as the form doesn't refresh, but becomes stale if the field is re-rendered by UI policies or AJAX updates.
Enjoying this? Get one deep-dive per week.
Join 1,000+ ServiceNow pros — scripts, GlideRecord patterns, Flow Designer techniques, and career moves. Free.
Platform Behavior & Side Effects
- No server-side code executes—this is pure client-side DOM access
- No database queries or updates are triggered by calling this method
- Performance is fast—direct object lookup in the client-side field registry
- Element references become invalid when UI policies re-render fields
- Works only in the classic UI—Service Portal and mobile apps use different DOM structures
- Direct DOM manipulation bypasses ServiceNow's change detection and validation
- Custom event listeners added to returned elements persist until form refresh