Help Needed in using sn-avatar in service portal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 02:03 PM
Hi All,
I am using the <sn-avatar> to populate the images/ initials of the person.It is working good when there is one user. When I am trying to add another user to the List, It is changing the Initials/ Image of both the persons instead of updating the avatar of the person added. If you see the below image, it is updating the initials of both the persons after I added a second user.
Help is appreciated.
Regards,
Dheeraaj
- Labels:
-
Service Portal Development

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2020 07:00 PM
Hi Dheeraaj,
I wrote a custom widget which looked for user's photos a while back. I ended up having to find and modify a function to pull them because there are different photos for a user's sys_user profile, and live profile. Here is my function:
var getPhoto = function(userID){
// Get the Sys ID of the user that we're retrieving the photo for
var user_id = userID;
//gs.log("getPhoto called for: " + user_id, "cf_LiveProfile");
var photo_path;
// Query for the live profile record
var live_profile_gr = new GlideRecord('live_profile');
live_profile_gr.addQuery('document', user_id);
live_profile_gr.query();
if(live_profile_gr.next()) {
if(live_profile_gr.photo.getDisplayValue()){
photo_path = live_profile_gr.photo.getDisplayValue();
//gs.log("Retrieved photo from live profile: " + photo_path, "cf_LiveProfile");
}
}
// Check to see if we have a photo from the profile
if(!photo_path){
// No profile photo found, query for the user photo
var user_gr = new GlideRecord('sys_user');
user_gr.addQuery('sys_id', user_id);
user_gr.query();
if(user_gr.next()) {
photo_path = user_gr.photo.getDisplayValue();
//gs.log("Retrieved photo from user record: " + photo_path, "cf_LiveProfile");
} else {
photo_path = '';
//gs.log("No photo found", "cf_LiveProfile");
}
}
return photo_path;
}
After calling the function for the user, you need to pass the result back and do an ng-if it exists:
<img ng-if="team_leader.photo" ng-src="{{team_leader.photo}}" src="no-user-photo.png" class="img-circle" style="width:158px; height:158px;">
Hope that helps,
Andrew
Please mark Helpful or Correct to assist others in finding the correct information. Thanks 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2020 10:05 AM
Hi Andrew,
I am able to successfully populate the user photos. However I was trying to use the sn-avatar directive to get the initials of the user if they don't have the photo.
It is working good when I add one user , but when trying to add multiple users, it is updating the photo of the second added user to the users already added to the list. see the attached image.
I want to know where can I see the code for this sn-avatar directive (OR) wanted to know if it was designed to function like this
Regards,
Dheeraaj