What does "typeof window == 'undefined' " mean?

ritaaudi
Tera Contributor

Hi: We have the following script in our 'Resolve Now' UI action that is called every time the user clicks the 'Resolve Now' button:

if (typeof window == 'undefined') {

  serverResolve();

}

I am wondering if something is wrong with the code. What is window == 'undefined'? Is it always 'undefined'? When is it 'defined'?

Thanks for your help!

Rita

1 ACCEPTED SOLUTION

Hi Rita,  



if(typeof window == 'undefined') means



1.Code that runs without 'onclick'.


2.Ensure call to server-side function with no browser errors


View solution in original post

10 REPLIES 10

Hi Rita,  



if(typeof window == 'undefined') means



1.Code that runs without 'onclick'.


2.Ensure call to server-side function with no browser errors


Hi Pradeep: Yes that makes sense. So the code in the if always executes unless there are browser errors. Thx! Rita


Hi Pradeep,



For my instance UI action 'Resolve Incident' also has onclick value - resolveIncident(); and this function has body in the script section. And your comment says "1.Code that runs without 'onclick'." how exactly it works? I am stuck for that point.


Hi Shreya,



Please go through below link for more info on how it works.


Client & Server Code in One UI Action - ServiceNow Guru



Let me know if you have any questions.


Thank you so much.. Now I am much clearer with this idea.. Thanks.