script

Karthik_Yallam1
Tera Contributor

How many ways we will call the Script include to the client script

1 ACCEPTED SOLUTION

Aditya02
Tera Guru

Hi @Karthik_Yallam1 ,


There are actually two ways to achieve this:

 

1. Using GlideAjax: This is the most common approach.

  • You create a GlideAjax object, specify the script include name, and call a function on the script include.
  • The script include returns a result, which you can then process in the client script.

2. Using the g_form object:

  • If the script include is specifically designed to work with forms, you can directly call its functions using the g_form object.
  • This method is more efficient and can be used for simple interactions with form-related script includes.

 

Here's an example of each method:

Using GlideAjax:

var ga = new GlideAjax('MyScriptIncludeName');
ga.addParam('param1', 'value1');
ga.addParam('param2', 'value2');
ga.get();
ga.addCallback(function() {
var result = ga.getAnswer();
// Process the result
});

Using the g_form object:

var result = g_form.callServer('MyScriptIncludeName', 'myFunction', 'param1=value1&param2=value2');
// Process the result

 

Choosing the right method:

  • GlideAjax: Use this method for general-purpose script include calls and when you need to pass parameters or handle asynchronous responses.
  • g_form object: Use this method for script includes that are specifically designed to work with forms and when you need to call functions directly from the client script.

 

===================================***************=========================================

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thanks & Regards,

Aditya

=====================================***********==========================================

 

 

View solution in original post

7 REPLIES 7

Anantha27
Mega Guru

hi @Karthik_Yallam1 

In ServiceNow, you can call a Script Include from a client script primarily using GlideAjax. Here are the main steps:

Create a Script Include: Ensure it is marked as client-callable.

Use GlideAjax in Client Script: Instantiate GlideAjax and pass the Script Include name and parameters.

Handle the Response: Use a callback function to process the response from the Script Include.

 

Thank you.

Manikanta Kota
Mega Guru

Hi @Karthik_Yallam1 

You can you script include in Multiple Ways in ServiceNow

1. GlideAjax

2. GlideRecord (server side)
3.Client  Script 
4.UI Actions

Should my answer prove to be helpful, kindly mark it as such by clicking "Accept as Solution" and "Helpful."

 

Regards,

Manikanta. Kota

Sai Krishna6147
Mega Guru

Hi @Karthik_Yallam1 

Please refer the link it may helps to you
Refer: 

GlideAjax | ServiceNow Developers

Script Includes | ServiceNow Developers

If you found my answer helpful, please give it a like and mark it as the accepted solution.

Regards,

Sai Krishna