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

Tony,


I ended up using a Client Script the following to protect my two fields when a ESS user was viewing a Resolved Incident. :



function onLoad() {


var state = g_form.getValue('state');


var objView = document.getElementById('sysparm_view');  


var strView = objView.getAttribute('value');  


  if ((strView == 'ess') & (state == '6')) {  


  g_form.setReadonly('comments',true);


  g_form.setReadonly('u_available',true);


  }


}



I also needed to hide the state field on the ESS user's view and did that with a UI Policy:



    function onCondition() {


var state = g_form.getValue('state');


var objView = document.getElementById('sysparm_view');  


var strView = objView.getAttribute('value');  


if (strView == 'ess') {  


  g_form.setVisible('state',false);


      }


}



So I ended up with a UI Page with a Client Script and a Processing Script.   The Client Script in the UI Page calls a GlideAjax Script Include to read the comment from the dialog box.




The goal of all this was this:   A user has had their incident resolved.   They receive an email notifying them it has been resolved and that they should go to the incident in order to "reopen" if they are not satisfied. (no instant reply links just a link to the incident itself).


When they get to the screen they can click on the "reopen incident" button and a confirmation dialog box is displayed.   The box has a text input for them to enter a comment and click 'yes' or they can 'cancel' the reopen.   The reason for all this was if the user could simply go to the form and enter a comment then we'd be dealing with a lot of emails to the Help Desk with "thanks!" or a question that might or might not even be related to the issue at hand etc.   This way if they want to reopen they need to state a reason and we'll only be dealing with true issues.   (We will also have a chance for them to respond positively via survey if that is what they would like to do.


Greg


Hello All,



Any body have any alternative to identify DOM object in FUJI. if Yes, can you please let me know.



or any body know how to change the style of an annotation on load of form?


BobbyNow
ServiceNow Employee
ServiceNow Employee

1) In a custom UI page, we let you manipulate the DOM by default.


2) In standard forms UI (eg client scripts, client ui actions) - by default we block access to the DOM and certain top-level globals (window, document, $ / jquery).   BUT: you can enable an application-specific property to gain access to the DOM.   This provides a good tradeoff since our default is a nice guard rail, and you must take explicit action to opt out (create a property).


With the explicit property, this allows us to do a few things: (a) on store submission, we know that an app wants raw DOM manipulation and can pay more attention to it in the certification process, (b) we can give it a lower "upgradability/maintainability" score, (c) can warn the developer on submission that they are going to need to re-certify the app on every major rls, etc.   But basically it allows us to deterministically know if an app wants to access the DOM.


So if you're writing some code that runs on a standard form, and require DOM access, add a property to your application with the following naming convention:



glide.script.block.client.globals=false


Hey Bobby,



Thanks for this response, this is much appreciated!



Thanks,


Tony


Hi bobby,



So if we want DOM Objects(forms UI (eg client scripts, client ui actions) to be used in Fuji ,we should create sys property as below ?  


glide.script.block.client.globals=false



please correct me ,if i am wrong.



thanks


Luxo