Can't access DOM, jQuery after having disabled "Isolated script"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 04:00 AM
Hello,
I wanted to perform DOM manipulation, for which I needed to access the DOM in my client script. After reading, I found that in order to have access to DOM and jQuery the form of the client script must be configured and the isolated script property must be set to false (unclicked).
However, upon doing so, trying to use document.getElementByID() throws an error in the console, 'document' is read as null. When trying to console.log(document), null is thrown in the console.
Why can't I access the DOM and jQuery still?
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 12:02 PM
Hi,
Please verify that the checkbox is actually false. If it's on the form, and you uncheck it, then save, go back and look again, there's times it gets rechecked after that first save, etc.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0743155
It does work, here's an example where I hide the "Add to Cart" button within a catalog item client script:
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 01:41 PM
Hi,
Thank you for your reply. I checked, the checkbox was indeed false, and document still receives the value of null. Might there be any other settings in the client script or system settings that could affect the accessibility of DOM?
Below is a summary of what happened. Isolated script is unchecked, the script is indeed running, as you can see there is '123' in the console. I get notified "There is a JS error in your browser console", and the error is as shown below.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 05:31 PM
Hello,
I'm glad my reply above was Helpful...as it got you to give more information and show a screenshot of your settings.
You're trying to use DOM manipulation via Client Script on the portal and "document" and several other methods aren't allowed:
You'd need to approach this differently.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2022 01:56 PM
Hello
Please have a look at the below article https://snprotips.com/blog/2017/7/21/how-to-enable-dom-manipulation-in-the-servicenow-service-portal
Please mark answer correct/helpful based on impact