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

Luxo, you are correct.


For any scoped application that requires DOM access to forms, etc. this property has to be created in its scope and set to false.


hi Bobby,


As you mentioned i have created the property glide.script.block.client.globals   and made it   true.



But still my below code is not working   as in eureka.




var e = document.getElementById("label.incident.u_alternate_contact_business");


  e.style.backgroundColor = '#CEF6EC' ;



thanks


Luxo


Please set the property to false and it should work.


hi Bobby,



Thanks for your Reply.But no luck this time too.


Tried   with another DOM object also as below  


document.getElementById('label.incident.number').style.backgroundColor='red';



I have used in onLoad Client script.In Eureka color changes to red,But in fuji no Luck .




thanks


Luxo


Luxo,


The property I provided allows you to use DOM manipulation. Beyond that you have to have a good understanding of the elements you are trying to modify to get the results you are after. I do not recommend setting styles on fields using this method because the elements and styles change frequently with releases. Something that works today may not work tomorrow as you see in the case of Eureka to Fuji. The element you are trying to set a background color on is a div which is the parent of the label element. In Fuji, the label element has classes that make it use style sheets that override styles from the parent node.



We provide the ability to style fields natively here: Defining Field Styles