Is having a client-callable Script Include mean that it cannot be called by server-side scripts?

Lhora Alvarez
Tera Sage

Hi all!

I have this question that keeps going around my head. I've been looking around the official docs and community, but I'm still not sure what's the right approach when it comes to calling your Script Include from both client-side and server-side.

 

I know that Script Include serves as your custom class. You use it to store and call all the reusable methods that your implementations (e.g. BR, Client Scripts) need to function.

 

So let's say that you have created a script include. This script include contains the same functions needed for both Server-side (e.g., BR) and Client-side (e.g., Catalog Client Script). It just needs to be called by the record itself.

 

Do you create 2 separate script includes (1 client-callable, the other is not), OR you create 1 client-callable script include that contains separate methods for client scripts (for GlideAjax to use) and server scripts?

 

Disclaimer: For the 1 client-callable script include, I've found community posts stating that your methods can be both server and client side. It's just a matter of checking where the parameter comes from.

 

I'm conflicted on what's considered best practice. If you can share your thoughts, that would be great.

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage
Giga Sage

HI @Lhora Alvarez ,
I trust you are doing great.
When you mark a Script Include as client-callable, it means that it can be accessed from the client-side scripts, like Catalog Client Scripts, using GlideAjax. This does not restrict it from being called on the server side. In fact, a client-callable Script Include can be used by both client-side and server-side scripts.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

5 REPLIES 5

Gunjan Kiratkar
Kilo Patron
Kilo Patron

Hi @Lhora Alvarez ,

 

You can call the same script include in client side as well as server side if client callable checkbox is checked. 

Client script syntax : 

 

var ga = new GlideAjax('name of Script include');
ga.addParam('sysparm_name','name of fucntion in script include');
ga.getXML(ResponseFunction);
function ResponseFunction(response)
{
here you get your response.
}

 

Server side :

 

 

var SI = new ScriptIncludeName.functionName();

 

 

You can refer below thread as well :

Script Function Available to BOTH Client side and Server side Code? 


Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

Ankur Bawiskar
Tera Patron
Tera Patron

@Lhora Alvarez 

it's possible but the reverse is not allowed i.e. if script include is not client callable then it can be only called from server side

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Amit Gujarathi
Giga Sage
Giga Sage

HI @Lhora Alvarez ,
I trust you are doing great.
When you mark a Script Include as client-callable, it means that it can be accessed from the client-side scripts, like Catalog Client Scripts, using GlideAjax. This does not restrict it from being called on the server side. In fact, a client-callable Script Include can be used by both client-side and server-side scripts.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi