Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Why does calling getElementById() return null?

jaraujo
Kilo Explorer

So I've been working on this UI Page that triggers off a button and is supposed to display a list of commands to be used in order based off the current record's information.  That part works and the commands are displayed.  However, one of the commands aren't displaying and after some research and testing, I still can't seem to figure out why.  At the top of the HTML portion of the UI Page, I have all the variables I need such as:

<g:evaluate var="jvar_u_ike_version" expression="RP.getWindowProperties().get('u_ike_version')"/>

Then much later on in the HTML portion of the UI Page, within a <script> block, I have this statement in JavaScript:

var ikeVersion = document.getElementById("jvar_u_ike_version");

Now, my question is why does this return null regardless of which variable ID I use even though in another <script> block before this one, I have a statement just like this one that returns the proper value and works fine?  Both <script> blocks are placed after all of the variable statements (like the one above) yet null still comes up.

5 REPLIES 5

Great. Mark this thread closed by marking your answer correct.


Please mark this response as correct or helpful if it assisted you with your question.