Why is GlideRecord not available in ClientScript in the Custom Application scope?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 11:49 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-02-2023 08:26 AM
The GlideRecord API is not available in ClientScripts for custom applications in ServiceNow due to architectural and security considerations. Here's the technical background on why this limitation exists:
Client-Side vs. Server-Side Execution:
- In ServiceNow, there is a clear distinction between client-side and server-side scripting. ClientScripts are intended for client-side scripting, which runs in the user's web browser, while GlideRecord is part of server-side scripting and runs on the ServiceNow server.
Security and Data Isolation:
- The ServiceNow server-side scripts, including GlideRecord, have access to the full range of data and system functionality. Allowing GlideRecord in ClientScripts would pose a significant security risk since client-side scripts run within the context of the user's session, and giving them access to GlideRecord would potentially expose sensitive data and actions to malicious client-side manipulation.
Performance Considerations:
- Server-side scripts like GlideRecord have the potential to execute complex and resource-intensive operations on the server. Allowing these operations to be triggered from the client side could lead to performance issues, as well as increased server load due to the lack of control and oversight.
Data Integrity:
- ClientScripts should primarily be used for tasks related to the user interface and client-side interactions. Allowing client-side scripts to manipulate server data directly could lead to data integrity issues if not carefully controlled.
To maintain a clear separation between client-side and server-side scripting, ServiceNow enforces these restrictions to ensure the security and stability of the platform. If you need to perform server-side data operations using GlideRecord, you should do so in server-side scripts, such as Business Rules, Script Includes, or Server-Side UI Actions, where the GlideRecord API is available.
If you have specific requirements that involve using client-side scripting and GlideRecord-like functionality, you may consider using AJAX or GlideAjax to make server-side calls from your client-side scripts
if you get answer please mark helpful and accept solution

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 01:53 AM
Hi there,
Here's an article that might be an interesting read for you. Hopefully after reading, you won't ever be tempted again to use GlideRecord in a Client Script.
- 2020-01-10 - Article - Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field