
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2019 10:55 AM
OK experts,
I was looking at Script Includes(SI) and I noticed that some SI have:
- an 'initialize: function()' and some do not.
- some of SI have functions inside of 'initialize: function()' and some have functions outside of 'initialize: function()'.
What does 'initialize: function()' actually do (because now I'm not sure), when do you use it (and when to not use it) and how to use it correctly?
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2019 11:00 AM
Mostly it's used for getting values that you might use in multiple function.
Like I use it to call system properties that has username or password stored so I don't have to call that properties in each function.
initialize: function() {
// Get authorization details
var authProfileID = gs.getProperty('auth_profile');
var authProfileGr = new GlideRecord('sys_auth_profile_basic');
authProfileGr.get(authProfileID);
this.soap_un = authProfileGr.getValue('username');
this.soap_pw = new GlideEncrypter().decrypt(authProfileGr.getValue('password'));
createContact: function (userGr) {
var s = new sn_ws.SOAPMessageV2('XXXXX', 'create');
// Set parameters for authentication
s.setStringParameterNoEscape("soap_un", this.soap_un);
s.setStringParameterNoEscape("soap_pw", this.soap_pw);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2019 11:00 AM
Hello Chris,
yes, initialize function is something like which holds the code that is made available to all the other functions defined over that script include
This links may help you to understand:
Scripting 101: Script Includes - Class vs Classless
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2019 11:00 AM
Mostly it's used for getting values that you might use in multiple function.
Like I use it to call system properties that has username or password stored so I don't have to call that properties in each function.
initialize: function() {
// Get authorization details
var authProfileID = gs.getProperty('auth_profile');
var authProfileGr = new GlideRecord('sys_auth_profile_basic');
authProfileGr.get(authProfileID);
this.soap_un = authProfileGr.getValue('username');
this.soap_pw = new GlideEncrypter().decrypt(authProfileGr.getValue('password'));
createContact: function (userGr) {
var s = new sn_ws.SOAPMessageV2('XXXXX', 'create');
// Set parameters for authentication
s.setStringParameterNoEscape("soap_un", this.soap_un);
s.setStringParameterNoEscape("soap_pw", this.soap_pw);