We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Using shared catalog client scripts

John Spencer
Tera Contributor

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

3 REPLIES 3

Juhi Poddar
Kilo Patron

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

Ankur Bawiskar
Tera Patron

@John Spencer 

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

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

Tanushree Maiti
Giga Sage

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

      https://www.servicenow.com/community/itsm-forum/what-is-ui-script-and-give-me-any-example-where-you-...

 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: