Using shared catalog client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello All,
Is there a 'reliable' mechanism to allow 'shared' code between / among catalog client scripts in the same catalog item?
That is, a client catalog script would load with the intent of being able to be called by another client catalog script in the same catalog item. Presently using Yokohama (patch 10).
Thanks in advance,
John Spencer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @John Spencer
You could consider using a UI Script to store the shared functions and then call those functions from your Catalog Client Scripts. This is a reliable way to reuse client-side code across multiple scripts and helps avoid duplicating logic.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
there is no available OOTB mechanism to control shared code between catalog client scripts.
You need to handle this with your development experience and customer requirement and try to avoid conflicting scripts.
Try to keep script in single onLoad always and you can write onChange script on variable based on requirement.
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Ankur’s answer is the most practical. While there is almost always a way to accomplish something through customization (for example, calling another Catalog Client Script from a client script), this pattern is generally discouraged. If you find yourself needing it, there is usually a better out-of-the-box approach, or the underlying use case should be reconsidered.
Ask first: why is shared client logic required? Often the goal is to avoid repeating the same logic, such as recalculations triggered by multiple onChange scripts.
If you truly need shared logic (e.g., calculations like infrastructure sizing for CPU or memory), a better approach is to implement the logic in a client-callable Script Include and invoke it via GlideAjax. Keep logic in client scripts only when the behavior is purely UI-driven.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi ,
In ServiceNow, a UI Script is a reusable block of client-side JavaScript code, similar to how a Script Include works for server-side code. They are used to promote code reusability and maintainability by centralizing common client-side functions like Client Scripts and Catalog Client Scripts.
Ref: https://www.servicenow.com/docs/r/api-reference/scripts/c_UIScripts.html
