What is the use of initialize :function(){} in Script include and How to write private function in Script Include?

ram2497
Tera Contributor

What is the use of initialize : function(){}  in Script include and How to write the private function in Script Include?

What is the difference between Client callable and Server Side calling in Script include, If we check Client callable any difference is there in script include.

 

Thanks

Ram

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@ram2497 

initialize function is something which holds the code that is made available to all the other functions defined over that script include.

private functions are something which are called in same scope of script include and not from outside

Refer below links for more help

Scripting 101: Script Includes - Class vs Classless

https://community.servicenow.com/community?id=community_question&sys_id=b31001c6db645b884e1df4621f96...

https://community.servicenow.com/community?id=community_question&sys_id=f5054f2ddbd8dbc01dcaf3231f96...

Regards
Ankur

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

Ankur Bawiskar
Tera Patron
Tera Patron

@ram2497 

Let me know if that answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

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

Hitoshi Ozawa
Giga Sage
Giga Sage

Explanation on initialize is provide in the following thread:

https://community.servicenow.com/community?id=community_question&sys_id=744608a4db17bb405129a851ca96...

 

"Client callable" in Script Include makes the script available to client:

Makes the script include available to client scripts, list/report filters, reference qualifiers, or if specified as part of the URL.

https://docs.servicenow.com/bundle/orlando-application-development/page/script/server-scripting/conc...

 

Also check difference between getXML() and getXMLAnswer() methods.

https://community.servicenow.com/community?id=community_question&sys_id=9495baf0db6fff80d58ea345ca96...

 

Difference in coding between Client Callable and Script Include. Script Include is now often recommended.

https://earlduque.com/2019/07/31/Client-Callable-and-Server-Callable-Script-Includes.html

 

Information on privacy of client-callable script

https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/security/referenc...

Megha Padale
Giga Guru

Hi Ram,

When we are writing code only for server side means client checkbox is not checked then we have a initialize function available in script include Class code. 
This initialize function is actually very useful. Whatever code we write in initialize () function then it will get execute every time when we create an object of script include class.
The initialize() function is basically the constructor for the initialized object.

var objDemo=new DemoScriptIncludeClass();

once we have initialized object objDemo of class DemoScriptIncludeClass as mentioned above then the code written in initialize () will get executed. 
I hope this helps to understand the concept.

Private function: 

Private function in script include is basically which is not accessible from client side. Private functions should have prefix “ _”. Below is the screenshot for the same:

Define Private Function in Script Include

 

To use script include servicenow at client side we have to make sure that client callable checkbox in script include interface should be checked and script include class should be extending class ‘AbstractAjaxProcessor’ (glide ajax – through which client script communicate with server-side script). 

If my answer helped you in any way, mark answer as helpful and correct.

Thanks and regards,

Megha.