is there any alternative for document.getElementById().innerHTML in client script ?

Nabil4
Kilo Explorer

 I need an alternative for document.getElementById().innerHTML in client side scripting. Since the DOM is method to avoid in servicenow 

3 REPLIES 3

Harsh Vardhan
Giga Patron

try with g_form.getControl('name');

 

Note: g_form.getControl('name') will not work on portal. 

Monali Patil
Kilo Guru

Hi, 

Nabil

 

The following globals and APIs are unavailable in service portal client script:

 

  • window
  • document
  • $
  • jQuery
  • $$
  • $j
  • angular

This means that if you are rendering a form in the service portal and you need to manipulate the look and feel of the form can be done on the ServicePortal side

 

- using a local CSS

 

- probably trying to work on the controller to have something similar to this

 

 

https://stackoverflow.com/questions/25738234/alternative-of-getelementbyid-in-angularjs

 

Thanks and Regards,

Monali Patil

Developer

find_real_file.png

 

 

Oleg
Mega Sage

It would be good if you describe the goal of usage document.getElementById().innerHTML in your code. If you really would need exactly document.getElementById().innerHTML, then you will don't find any better way, because all other ways (for example usage jQuery or angular) uses the same document.getElementById().innerHTML internally. Thus all alternative ways will be slowly.

On the other side if you describe your scenario (the use case) where you use document.getElementById().innerHTML and why you are not satisfied then one suggest you some alternative or to explain why the current way is the best one.