Alternative for DOM Manipulation in client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 11:46 PM
Hi All,
I have used g_form.getControl() method in client script, as it's not a best practice. If there is any alternative for DOM manipulation, reply back on the post. It will be really helpful.
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 12:03 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2024 12:20 AM
@prerna_pandey According to ServiceNow best practices
"Avoid Document Object Model (DOM) manipulation if possible. It can cause a maintainability issue when the instance is updated. when using DOM manipulation methods, you have to reference an element in the DOM by id or using a CSS selector. When referencing out-of-box DOM elements, there is a risk that the element ID or placement within the DOM could change thus causing the code to stop working and/or generate errors."
Source: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0954537
Hence there is no good/bad approach when it comes to DOM manipulations. It is not recommend to do DOM manipulations at all in ServiceNow.