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

Kieran Anson
Kilo Patron

Hi Ram,

the initialize function is called everytime when the script is instantiated so any code within the function is executed no matter the sub-function that is called via the external script. This is useful for declaring re-usable variables, starting logging etc.

Javascript doesn't have a concept of private and public functions like Java. If you're referring to pieces of code you don't want externally executed or called, this is denoted by the function name starting with an underscore: _myinternalfunction: function(){}.

Client callable allows calls from client scripts, client UI actions and service portal and are instantiated by the GlideAjax API.

Hi, Checking in on whether you need anymore assistance with this issue?

If my reply helped with your issue please mark helpful ???? and correct if your issue is now resolved.
By doing so you help other community members find resolved questions which may relate to an issue they're having.

Sudhanshu Talw1
Tera Guru

Hi,

 initialize:function() works like constructor in the class.

private function=> _getDetails():function(){} consider as a private function as it starts with _

This is servicenow convention.

 

Client callable is basically checked on when you want your Script include works like a Async Call that means if you want your SI will return data to a UI form make it client callable otherwise not required.

Like if I call a script include in reference qualifier it is not needed to mark as client callable as we access it via className.functionName

but if it returns data & we want to set the data on the fields we have to make it client callable so that it can be called by the client side via GLIDEAJAX API.

 

 

Thanks

Sudhanshu

Hi,

Hope you are doing well.

Is it answered your question?

If yes please mark it correct & close the thread.

 

Thanks

Sudhanshu