Fuji client scripts: document object is null

aklimenko
Mega Expert

Hi

We use document.getElementById() or gel() in client scripts to get controls. In some places we cannot replace it with g_form. For example, I need to get a catalog item sys_id in variable set client script so the only way I could do that was document.getElementById("sysparm_id").value

What I found out is that for any client script document object is null:

[Error] TypeError: null is not an object (evaluating 'document.getElementById')

Any ideas?

42 REPLIES 42

Hi Bobby. In the case I need to hide the reference icon, what would you advise me to use? I can't find anything to manipulate it without using DOM manipulation.



Thks


BobbyNow
ServiceNow Employee
ServiceNow Employee

What is the use case? What is the end result you are trying to achieve?


I need to hide the reference icon after I completed a field. Previously I solved it with a client script doing this:



document.getElementById('view.u_database_access_matrix').style.display = 'none';



But now when I do that I get the following error:



onChange script error: TypeError: Cannot read property 'style' of null function h_670bfe81c058420087da1d9d5b48a32e(control, oldValue, newValue, isLoading)


BobbyNow
ServiceNow Employee
ServiceNow Employee

I understand you want to hide the icon, I was hoping for some insight on why you want to hide it.


Depending on the end result you are after with your overall solution this may be a step you do not need.



If you must hide the icon, a safe way to do so would be to set the field as readonly.


This will not work if the property referenced in the wiki below has been modified.


http://wiki.servicenow.com/index.php?title=Customizing_the_Reference_Icon#Pop-Ups_on_Read-Only_Field...


Bobby, we want to hide that field, because it is bringing information from a custom table, and we don't want the customer to see that.



What you proposed hides the magnifying glass icon, not the reference one (the one with the "i"). I'm attaching an image of the icon I want to hide so there's no more confussion about it.


Icon.PNG



Thanks!