Parameters in script include initialize function

rai5
Mega Guru

Hello, 

 Can someone explain what the lines of code bellow mean in the script include sn_hr_core.hr_Profile? Why is this even needed, what is the purpose of this?

 

 

hr_Profile.prototype = {
			initialize: function(_gr, _gs) {
				this._gr = _gr;
				this._gs = _gs || gs;
			},
	
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

they have initialized the global variables this._gr so that it can be used in multiple function within same script include.

initialize() function holds code which can be available to all other functions in that script include

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

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

they have initialized the global variables this._gr so that it can be used in multiple function within same script include.

initialize() function holds code which can be available to all other functions in that script include

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

Thanks Ankur, I do see that _gr is passed as a glide record in the example bellow; however I do not understand what gs accomplishes with sufficient clarity. The code bellow is for a UI action on the sys_user table that creates a human resource profile for the user. 

 

current.update();
var profile = new hr_Profile(current, gs).createProfileFromUser(current.sys_id);
if (profile)
	action.setRedirectURL(new hr_Profile(current, gs).getProfileFromId(profile));

I also found this: 

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

 

Kind of obvious but needed to wrap my head around the concept that you can reference the gs object and then use it in a script include. such as in the example bellow from the hr_profile script include.

 

// Check the hr role
	if (this._gs.hasRole(hr.ROLE_HR_PROFILE_READER))
		return true;