Name
sn_hr_core.hr_CustomAdapterUtilsSNC
Description
No description available
Script
var hr_CustomAdapterUtilsSNC = Class.create();
hr_CustomAdapterUtilsSNC.prototype = {
initialize: function() {},
/**
* Description: Gets the corresponding sys_user sysId of the ChannelUserProfile from provideruserId
* @param {SysID} proivderUserId
* @return {SysID} sys_user sys_id
*/
getUserFromChannelUserProfile: function(providerUserId) {
var channelUserProfileGr = new GlideRecord('sys_cs_channel_user_profile');
channelUserProfileGr.addQuery('channel_user_id', providerUserId);
channelUserProfileGr.addActiveQuery();
channelUserProfileGr.query();
if (channelUserProfileGr.next() && channelUserProfileGr.getValue('user_table') == 'sys_user')
return channelUserProfileGr.getValue('user_document');
return null;
},
/**
* Description: Verifies if there is HR profile for given active sys_user
* @param {SysID} sysId of sys_user
* @return {boolean} true/false
*/
isUserLinkedToHrProfile: function(userId) {
if (!gs.nil(userId)) {
var hrProfileGr = new GlideRecord('sn_hr_core_profile');
hrProfileGr.addQuery('user', userId);
hrProfileGr.addQuery('user.active', true);
hrProfileGr.query();
if (hrProfileGr.hasNext())
return true;
}
return false;
},
/**
* Description: Verifies if there is active HR profile for given proivderUserId
* @param {SysID} proivderUserId
* @return {boolean} true/false
*/
isProviderUserIdLinkedToHrProfile: function(providerUserId) {
var userId = this.getUserFromChannelUserProfile(providerUserId);
return this.isUserLinkedToHrProfile(userId);
},
/**
* Description: updates the ChannelUserProfile with HR profile sys user if guest channelprofile exists with providerUserId
Updating the interaction opened_for updates the corresponding channel User profile through BR on interaction
* @param {SysID} proivderUserId
* @param {GlideRecord} profileGr
*/
_updateChannelUserProfile: function(providerUserId, profileGr) {
var channelUserProfileGr = this._getGuestChannelUserProfile(providerUserId);
if (!gs.nil(channelUserProfileGr) && channelUserProfileGr.isValidRecord()) {
var interactionGr = new GlideRecord('interaction');
interactionGr.addQuery('channel_user_profile', channelUserProfileGr.getUniqueValue());
interactionGr.query();
if (interactionGr.next()) {
interactionGr.setValue('opened_for', profileGr.user);
interactionGr.update();
}
}
},
/**
* Description: updates the existing guest ChannelUserProfile with the HR profile user if match found
* @param {GlideRecord} current
* @param {GlideRecord} previous
*/
updateChannelUserProfileFromWorkNumber: function(current, previous) {
this._updateChannelUserProfile(current.work_mobile, current);
},
/**
* Description: updates the existing guest ChannelUserProfile with the HR profile user if match found
* @param {GlideRecord} current
* @param {GlideRecord} previous
*/
updateChannelUserProfileFromMobileNumber: function(current, previous) {
this._updateChannelUserProfile(current.mobile_phone, current);
},
/**
* Description: Gets the ChannelUserProfile from provideruserId if user document is empty
* @param {SysID} proivderUserId
* @return {GlideRecord} channeluserProfileGr
*/
_getGuestChannelUserProfile: function(providerUserId) {
var channelUserProfileGr = new GlideRecord('sys_cs_channel_user_profile');
channelUserProfileGr.addQuery('channel_user_id', providerUserId);
channelUserProfileGr.addNullQuery('user_document');
channelUserProfileGr.addActiveQuery();
channelUserProfileGr.query();
if (channelUserProfileGr.next())
return channelUserProfileGr;
return null;
},
type: 'hr_CustomAdapterUtilsSNC'
};
Sys ID
44645293539a10100ad0ddeeff7b12c4