- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 08:59 PM
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;
},
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 09:09 PM
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
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 09:09 PM
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
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2022 06:43 PM
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));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2022 07:18 PM
I also found this:
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;