Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Alternative for DOM Manipulation in client script

prerna_pandey
Giga Contributor

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!

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@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.