Name

global.UserProfileService

Description

No description available

Script

var UserProfileService = Class.create();
UserProfileService.prototype = {
  initialize: function() {
  },
  
  appLiveProfile: new GlideappLiveProfile(),
  
  getProfile: function(userId, userName) {
  	var name = String(userName);
  	var profile = {};
  	profile.id = userId;
  	profile.text = name;
  	profile.imgUrl = '';

  	name = name.replace(/[^\w\s\.]\w+[^\w\s\.]|[^\w\s\.]/, "");
  	name = name.replace(/\s+/, ' ');
  	var parts = name.split(' ');
  	if(parts[0] && parts[1]) {
  		profile.initials = (parts[0].substring(0, 1) + parts[parts.length - 1].substring(0,1)).toUpperCase();
  	} else {
  		profile.initials = parts[0].substring(0, 1).toUpperCase();
  	}

  	return profile;
  },
  
  getAvatarFromDB: function(profileId, profileTable) {
  	var gr = new GlideRecord('sys_attachment');
  	gr.addQuery('table_sys_id', profileId);
  	gr.addQuery('table_name', 'ZZ_YY' + profileTable);
  	gr.query();
  	if ( gr.next() )
  		return (gr.sys_id + '.iix');

  	return "";
  },
  
  generateProfile: function(userId) {
  	var profile;
  	var profileId;
  	var profileName;

  	profileId = this.appLiveProfile.getID(userId);
  	profileName = this.appLiveProfile.getName(profileId);
  	profile = this.getProfile(userId, profileName);

  	profile.imgUrl = this.appLiveProfile.getAvatar(profileId);

  	if(JSUtil.nil(profile.imgUrl) || profile.imgUrl.indexOf('default') > -1) {
  		profile.imgUrl = this.getAvatarFromDB(userId, 'sys_user');
  	}

  	return profile;
  },
  
  type: 'UserProfileService'
};

Sys ID

0efb5d910f09230096f9d6892f767e6f

Offical Documentation

Official Docs: