Reuse client side code in portals

cdarsow
Tera Contributor

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

 

 

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@cdarsow 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Tanushree Maiti
Giga Patron

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 

 

https://www.youtube.com/watch?v=fyMA-E-kouY

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:
In this Share the Wealth session, Associate VP of Professional Services David Arbour provides an overview and demonstration of reusable UI scripts in ServiceNow. UI scripts provide a way to package client-side JavaScript into a reusable form, similar to how script includes store server-side ...