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

Dubz
Mega Sage

Hi Abed,



You can write a client script on the table that is being referenced by these other pages and and if you tick the 'Inherited' box it will apply that script for all extended tables.



For example, i have a client script ensuring correct formatting on the IP address field on the cmdb_ci table, this is inherited by all tables extending cmdb_ci so i don't have to replicate the script for all CI classes using that field.



It depends on what your requirements are but this might be something you can use, just remember that this will apply to all extended tables so be sure this won't cause unexpected consequences elsewhere!


divya mishra
Tera Guru

Better option would be :
You can write the same client script on the client script section of the ui pages and make a common repository of code in the Script Include to access the table data.Call the script include there in the client scripts


how can i make   common repository ?


Short answer: UI Scripts


By common repository I mean Script Includes that holds the reusable codes.