Script Includes: provide use case to understand !!

ZebaT
Tera Contributor

Hi all,

I'm trying to understand difference between script include and client ajax. Script include is for server side calling of same script and glideajax is similiar to script include but used to call this script on client scripts. Is my understanding correct?

Can you provide one or two use real  case for each which can help clear my confusion.

RThanks

6 ACCEPTED SOLUTIONS

Mohammed8
Giga Sage

Hi @ZebaT 

I don't have real use case / live project use case to cite but i can share use case for Glide Ajax which I tried out in PDI.

 

Use Case: Incident Count of Selected Configuration Item with Info Message and Link to its Related Incident. Displays a message showing the count of open incidents associated with a selected Configuration Item (CI) whenever the Configuration Item field changes on the Incident form. Glide Ajax used as it calls the script from client side when interacting with incident form.

 

  • Helps quickly identify whether the selected CI has existing incident by fetching and displaying active incident counts (excluding Resolved, Closed, and Canceled states).

  • Shows an info message with a clickable link that opens a filtered list of related incidents for that CI

  • If more than five incidents are linked, a warning message appears suggesting Problem investigation for frequent or repeated CI issues.

  • Uses an onChange Client Script on the Configuration Item field and a GlideAjax Script Include called from the client script to fetch the incident count

Mohammed8_4-1766682718951.png

 

Mohammed8_5-1766682737850.png

 

Similarly a Script Includes is reusable server-side code which the server side and can be called by Business Rules , job schedules etc..

 

Here is link for blog for your better understanding:

https://www.servicenow.com/community/developer-advocate-blog/client-callable-and-server-callable-scr...

If you find this useful please mark it as helpful/solution accepted

 

Thanks and Regards,

Mohammed Zakir

View solution in original post

Ankur Bawiskar
Tera Patron

@ZebaT 

In simple terms GlideAjax is the way to invoke client callable script include from Client side code such as Client Scripts, UI Policy Script etc

without GlideAjax you can't call script include.

Real-time scenarios:

-> Consider you need to perform some onChange validation on some field based on some server side logic, you need to use GlideAjax and you can show error near the field if validation fails

-> Consider you have a reference field and some other fields on form and you want to bring data from the reference fields and auto populate in form fields, here you will use GlideAjax

💡 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

nayanmule
Kilo Sage

@ZebaT  , in simple words "GlideAjax" is a client side API used to make synchronous/asynchronous calls to  server side. GlideAjax helps you to fetch the data from Script includes and use it in UI. i.e client side.

 It acts as a bridge, letting client-side JavaScript communicate with server-side logic .

 

Example - If you have a reference field through which you would need to fetch the data from the reference field's table, you can make use of GlideAjax. It's considered as a best practice rather than using .getReference().

 

Example - Also the most common example is used for doing certain date valdiations, as GlideDate() is not supported in Client scripts. Hence, we can use the script include and call the function in client script using glideajax.

 

Here is the syntax used - 

var ga = new GlideAjax('YourScriptIncludeName');  //Creates the GlideAjax object
ga.addParam('sysparm_name', 'yourFunctionName'); //Specifies the function in the Script Include to run
ga.addParam('sysparm_yourParam', 'value');  //Passes data to the server
ga.getXML(yourCallbackFunction);  //Sends the request and waits for the response

 

If my response has helped you, kindly mark as helpful and accept the solution.

Regards,

Nayan

View solution in original post

Nikhil Bajaj9
Tera Sage

Hi @ZebaT ,

 

Let me try to tell you in very simple language - We have Client side scripts (Frontend - Form/catalog)and Server side scripts (Gettign data from Tables/database). Do we have anything to communicate between these two? What if i am at front end ex:- Incident Form where i have caller but now i want to get the caller's Manager or Company or Location etc. and want to display these on incident form. How can i fetch these details as thesse details are in user table and can be fetched using server side scripts only. Server side scripts will fetch these details but how it will pass these details to frontend (Incident for in this case). There is no way to call Business Rules/script include in client side scripts. Here comes the Glide Ajax - Which will get the data from Server side/table and will provide this data to frontend /Incident form. So Glide ajax is a way of communication/exchanging data between Server side and frontend/client side.

I hope this real use case and explaination will make it clear. If you still have any query, please ping me back.

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

ServiceNow Rising Star-2025

View solution in original post

adityahubli
Tera Guru

 

Hello @ZebaT ,

 

Script Include is reusable server-side code in ServiceNow.
There are three types of Script Includes:

  1. On-Demand / Classless Script Include

    • No need to create an instance of a class

    • We can directly call the Script Include function

  2. Defining a New Class (Standard Script Include)

    • We must create an object of the Script Include class

    • Using that object, we can call the class methods

  3. Extends an Existing Class

    • Commonly used with GlideAjax

    • Helps fetch server-side data and use it on the client side

For complex scenarios where we cannot use getReference() (deprecated) or g_scratchpad, we use GlideAjax.

📌 Common Use Cases / Scenarios

  • Return a dynamic Assignment Group list based on Category using Script Include

  • Auto-populate Manager’s Name using GlideAjax + Script Include when Caller is selected

  • Use Script Include + UI Action to count total records (Incident, Change, Problem, Task)

  • Restrict assignment if an assignee already has 5 or more active tickets (via Script Include)

  • Prevent duplicate records (same Category + Short Description) using Business Rule or Script Include

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical Consultant

View solution in original post

8 REPLIES 8

Rushi Savarkar
Mega Sage

Hello @ZebaT 

Just refer to the two simple use cases below.

1. https://www.servicenow.com/community/developer-forum/script-include-call-is-not-working-from-sow/m-p...

2. https://www.servicenow.com/community/app-engine-forum/auto-populate-location-field-on-catalog-item-v...

Thanks!

If my response helped you, please accept the solution and mark it as helpful.
Thank You!

Nikhil Bajaj9
Tera Sage

Hi @ZebaT ,

 

Let me try to tell you in very simple language - We have Client side scripts (Frontend - Form/catalog)and Server side scripts (Gettign data from Tables/database). Do we have anything to communicate between these two? What if i am at front end ex:- Incident Form where i have caller but now i want to get the caller's Manager or Company or Location etc. and want to display these on incident form. How can i fetch these details as thesse details are in user table and can be fetched using server side scripts only. Server side scripts will fetch these details but how it will pass these details to frontend (Incident for in this case). There is no way to call Business Rules/script include in client side scripts. Here comes the Glide Ajax - Which will get the data from Server side/table and will provide this data to frontend /Incident form. So Glide ajax is a way of communication/exchanging data between Server side and frontend/client side.

I hope this real use case and explaination will make it clear. If you still have any query, please ping me back.

 

Please appreciate my efforts, help and support extended to you by clicking on – “Accept as Solution”; button under my answer. It will motivate me to help others as well.
Regards,
Nikhil Bajaj

ServiceNow Rising Star-2025

adityahubli
Tera Guru

 

Hello @ZebaT ,

 

Script Include is reusable server-side code in ServiceNow.
There are three types of Script Includes:

  1. On-Demand / Classless Script Include

    • No need to create an instance of a class

    • We can directly call the Script Include function

  2. Defining a New Class (Standard Script Include)

    • We must create an object of the Script Include class

    • Using that object, we can call the class methods

  3. Extends an Existing Class

    • Commonly used with GlideAjax

    • Helps fetch server-side data and use it on the client side

For complex scenarios where we cannot use getReference() (deprecated) or g_scratchpad, we use GlideAjax.

📌 Common Use Cases / Scenarios

  • Return a dynamic Assignment Group list based on Category using Script Include

  • Auto-populate Manager’s Name using GlideAjax + Script Include when Caller is selected

  • Use Script Include + UI Action to count total records (Incident, Change, Problem, Task)

  • Restrict assignment if an assignee already has 5 or more active tickets (via Script Include)

  • Prevent duplicate records (same Category + Short Description) using Business Rule or Script Include

If this helps you then mark it as helpful and accept as solution.

Regards,

Aditya,

Technical Consultant

Shashank_Jain
Mega Sage

Hii @ZebaT ,

 

In simple words,

GlideAjax is a client side mechanism to call server side script to fetch the data without reloading the form.

 

When we use GlideAjax :

After the form loads.

Basically on user interaction (OnChange Client script or onClick UI Action)

 

Where not to use GlideAjax :

When the form load ( We use g_scratchpad there)

After the form save (Use Business rule )

 

Good example of GlideAjax usage:

When we want to validate, on change of caller_id, whether the caller is a VIP:

  • Use an onChange Client Script

  • Send the caller_id to a server-side Script Include using GlideAjax

  • Check whether the caller is VIP on the server side

  • Return the result to the client

  • Show an alert message if the caller is VIP

Hope it helps you!

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain