Can a normal script include be converted to client callable ?

Amarendra
Mega Contributor

What will happen if an existing normal script include be made client callable(by checking the box) and changing the prototype line accordingly ? I tried the same in Geneva instance and was able to call it from the client script using GlideAjax, but the value returned was 'null'. Please help me to understand the reason behind it.

4 REPLIES 4

BALAJI40
Mega Sage

If it was server side script include, you can make it client callable also, but you should change the prototype to client callable prototype.


If you do like that you can use it in both server side and client side as well.



prototype :testScriptInclude


name:


client callable: yes



var testScriptInclude = Class.create();


testScriptInclude.prototype = Object.extendsObject(AbstractAjaxProcessor, {



test1ClientSide: function(){},// client callable code


test1ServerSide: function(){},//Server side code


      type: 'testScriptInclude'


});


Chuck Tomasi
Tera Patron

As a best practice, I would keep your base/core logic in a server side script include and call it's functions/methods from within a new client callable script include. This allows you leverage that core logic in the server side script include from other places like UI actions, workflow scripts, business rules, etc. while still extending it to clients via the client callable Ajax script include.



client script --> client SI --> server SI



I believe sabell2012 did an Ask the Expert session on this, however I cannot seem to find it this morning.


Thanks for the mention Chuck!



Amarendra:



You want to keep two things in mind when connecting up the client/browser-side to the server-side:



1. Use GlideAjax to do this.


2. Use Asynchronous callbacks to keep from locking up the user while the server is doing the requested work.



A good starter article on this is in the ServiceNow Docs:


Examples of asynchronous GlideAjax



Additionally, if you end up creating the same code over-and-over look at using a UI Script to create reusability and simplify maintenance.   I did an ask-the-expert, and also published a couple of best-practice articles on this.



The following article describes creating a UI Script (client side Script Include), that centralizes your often-called client side functions:


Ask the Expert: Posting Log Information from Client to the System Log via Ajax with Steve Bell



The following lab article guides you on how to accomplish creating your first UI Script library:


Mini-Lab: Writing Entries Into the System Log Using Ajax and JSON




The following article describes the entire pattern being used:


Pragmatic Patterns: Ajax - Architecting Your Code



Hope that helps!



Steven Bell


See you all at K17!


Community Code Snippets: Articles List to Date


I like it when when Best practices are recommended with answers