Can i write common code for 2 client scripts ?

abed_masrawa
ServiceNow Employee
ServiceNow Employee

Hi

I have 2 pages that have data from one table in the DB.

I want to write client script for the 2 pages.

Can i write 1 client script for the 2 pages ?   or to write the same script include twice ?

1 ACCEPTED SOLUTION

Script includes are for server side code libraries. UI scripts are the client side counterpart. You need to use a UI script to store your common code that you call from the various client scripts.


View solution in original post

12 REPLIES 12

Kalaiarasan Pus
Giga Sage

When you say 2 pages, are these different screens/forms of same table?


yes ,


deferent screens, that i need to write in the both screen the same client script.


abhishekdash
ServiceNow Employee
ServiceNow Employee

Hello Abed,



You can leverage UI Scripts to implement similar use cases.


Please check below documents and see if it helps:



https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/script/client-scripts/concept/c...



Hope this helps.



Thanks,


Abhishek



If this reply assisted you, please consider marking it Correct, Helpful, or Like it.


This helps other customers to learn from your thread.


Chuck Tomasi
Tera Patron

Hi Abed,



Take a look at UI Scripts. They are a "library" that you can call. Yes, you'll have some similar code to CALL the functions in the UI script, but it's not duplicate code per se. UI scripts are similar to their server counterpart called script includes.



https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/script/client-scripts/concept/c_...