Why is GlideRecord not available in ClientScript in the Custom Application scope?

Takakazu Sato
Tera Contributor

The following error occurred when using GlideRecord within a ClientScript created in a scope application.

 

Error:「onChange script error: TypeError: GlideRecord is not a constructor function () { [native code] }」

 

I believe the error is due to the use of GlideRecord within the ClientScript created in the custom scope application.

I would appreciate a technical explanation. (Because it crosses a scope boundary?)

 

Also, if I create a GlideRecord part in a ScriptInclude and call that ScriptInclude from ClientScript, I no longer get the above error, but why is the error no longer occurring?
Please let us know.

 

 

 

 

6 REPLIES 6

Maik Skoddow
Tera Patron
Tera Patron

Hi @Takakazu Sato 

please understand the difference between server-side code where GlideRecord API is located and client-side code which is running only in the browser. Yes, it is possible to use a GlideRecord API on client-side, but it is not recommended.

And without more details from your side (where is the code example?) it's possible to help you.

Maik

Harish Bainsla
Tera Sage
Tera Sage

Client-side GlideRecord is massively inefficient, far too slow, and returns way too much unnecessary data to be used commonly in production code. GlideAjax is simply the best and most efficient method for looking up data from client-side scripts.

https://www.servicenow.com/community/developer-forum/why-it-is-not-good-to-use-gliderecord-in-client...

https://www.servicenow.com/community/developer-forum/gliderecord-client-is-it-best-practice-to-use-g...

Mohith Devatte
Tera Sage
Tera Sage

Hello @Takakazu Sato ,

Yes GlideRecord API  is available on client scripts but it is not at all recommended to use a GlideRecord API in client side .You need to minimise server calls to avoid the performance issue 

 

GlideRecord and g_form.getReference() callback are also available for retrieving server information. However, these methods are no longer recommended due to their performance impact. Both methods retrieve all fields in the requested GlideRecord when most cases only require one field. The GlideRecord API is not available for scoped applications.

 

See the points highlighted in red .For scoped or custom apps glide record api is not available on client scripts and this is the reason you are getting this error .So only way is to call a script include via GlideAjax.

 

For more best practices on client scripts follow this link

https://developer.servicenow.com/dev.do?_escaped_fragment_=/guides/utah/now-platform/tpb-guide/clien....

 

 

Hope this helps 

Mark the answer correct if this helps you 

Thanks

 

Thanks for the reply.
Please tell me one thing: GlideRecord API is not available in ClientScript for scoped custom applications.


Why is the GlideRecord API not available in ClientScript for custom applications? I would like to know the technical background.