The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Can't access DOM, jQuery after having disabled "Isolated script"

T_Fesenko
Tera Contributor

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?

find_real_file.png

find_real_file.png

5 REPLIES 5

Allen Andreas
Administrator
Administrator

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:

find_real_file.png

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

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. 

find_real_file.png

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:

https://docs.servicenow.com/bundle/quebec-servicenow-platform/page/build/service-portal/concept/unsu...

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!

Saurav11
Kilo Patron
Kilo Patron

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