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 Alexey,


I think g_form.getUniqueValue(); is working fine.




Please create one client script on catalog variable.


Screen Shot 2015-03-12 at 2.57.05 PM.png



1>Open catalog item


2>Give values in varibale and oreder that catalof item


3>Open the ritm ticket for that catalog item, you will get alert with sys_id of that record like below.


Screen Shot 2015-03-12 at 3.00.24 PM.png



Thanks,


Pavan


It may work on request item form but I need sys_id of the current catalog item on the same page where I enter variables. In you example Step1 and Step2 before ordering. I need to know sys_id to fill in some variable defaults.


Just to give more details why we do it this way.


1. Our catalog items contain custom fields and share the same variable set


2. When a person orders an item he needs to put some values into variables


3. There is also a number of client scripts that make decisions for what variables to show and what default values to set. These scripts need to have access to the requesting catalog item to read data from custom fields. That's why I need to pass somehow sys_id of the catalog item at this stage.


4. Only then do user orders the item


BobbyNow
ServiceNow Employee
ServiceNow Employee

Alexey,


Looking at your use case I believe you can accomplish your goal without client scripts.


You can use UI Policies against each catalog item that control questions even if they are from variable sets.


If you had to use a client script you could apply it to the specific catalog item as well.



I did verify that g_form works in FP2, but getUniqueValue is not populated with the sys_id.


g_form can be used for getting question values though.



I will request that we populate getUniqueValue with the catalog item sys_id in a patch, but not sure it is needed in this case.


Please let me know if I have missed something about your logic.


Thank you , Bobby. My logic is not mainly to show, hide variables (for these I use UI Policies). I need to populate initial values of variables based on some server logic. I pass catalog item id to server script include, it does its magic and returns values to populate variables with. Even if I use javascript: constrict in default field of a variable I will still need to have access to catalog item definition to get some data from it for decision making. Hope it helps to understand...