Reuse client side code in portals
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi,
being a Servicenow newbie I wonder, how to create and (re-)use client side JS code for a portal solution.
What I thought to understand: create an UI script for shared code and mark it as usable for UI type "Portal":
https://www.servicenow.com/docs/r/xanadu/application-development/scripts/c_UIScripts.html
Trying to load that script then within a Catalog client script results in an error as g_ui_scripts seems not to be supported here. Is my assumption right, that this way of loading does not work here?
How is the way to provide the UI script in a global way, so that I can access it in record producer scripts (Catalog client scripts) and/or widgets? Actually I just want to provide our own kind of tool-library and don't want to code the same lines over and over again...
I really wonder why it is so hard to get to understand how clean coding works in the platform 🙂
Thanks for your help,
best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
check below
[SOLVED] How to call scoped UI script from catalog client script ?
Avoiding code duplication in Catalog Client Scripts
also this
Call UI script from an Onload Catalog client script
Service Portal UI Script or Reusable functions in Client Scripts
💡 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
an hour ago
Hi @cdarsow
You are on correct path.
To create and reuse client-side JavaScript in a ServiceNow Service Portal, the most effective method is using UI Scripts. These act as the client-side equivalent of Script Includes, allowing you to package logic that can be shared across multiple widgets or pages
Refer: Servicenow Documentation: UI scripts