Script Includes but for Client-side code?

JeremiP
Tera Guru

Hi,

I was wondering if there's any module or platform functionality that resembles Script Includes, but runs the code on the client-side?

 

In my use case, I need to reuse the same verification of inputs and then make a GlideAjax call on two Catalog Client Scripts running on two separate fields.

The fields are:

- VAT - read-write

- Netto - read-write

- Brutto - read-only, to be written to by g_form.setValue

On changes of either VAT or Netto, I'd like to trigger the same calculation and write the received value to Brutto, or handle any errors/incorrect returns within the shared function. It doesn't need to happen on the server-side in this instance, but let's say I may need to use the same way of thinking in the future where this is necessary.

 

I'm asking about this because I've started to look for more ways to simplify maintenance. If there's more than one place with the same code snippet, perhaps it could be placed in a shared library, just like Script Includes?

 

The code also needs to execute on both backend and front-end (SP/EC), so if it's not accessible from either platform, it's a no go.

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@JeremiP  Client side equivalent of Script Include is UI Script. UI scripts provide a way to package client-side JavaScript into a reusable form, similar to how script includes store server-side JavaScript. Administrators can create UI scripts and run them from client scripts and other client-side script objects and from HTML code.

 

For more information please refer to https://docs.servicenow.com/bundle/utah-application-development/page/script/client-scripts/concept/c...

 

Hope this helps.

View solution in original post

1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@JeremiP  Client side equivalent of Script Include is UI Script. UI scripts provide a way to package client-side JavaScript into a reusable form, similar to how script includes store server-side JavaScript. Administrators can create UI scripts and run them from client scripts and other client-side script objects and from HTML code.

 

For more information please refer to https://docs.servicenow.com/bundle/utah-application-development/page/script/client-scripts/concept/c...

 

Hope this helps.