Skip to content

Commit ce199be

Browse files
authored
Script Include: Get Profile Picture (#1642)
* Create Get Profile Picture * Rename Get Profile Picture to Get Profile Picture.js * Rename Server-Side Components/Script Includes/Get Profile Picture.js to Server-Side Components/Script Includes/Get Profile Picture/GetProfilePicture.js * Rename GetProfilePicture.js to getProfilePicture.js * Create README.md
1 parent 44eb232 commit ce199be

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Retrieves the user photo from the Live Profile, if possible, otherwise gets the photo from the user record if possible.
2+
Returns the path to the photo or an empty string
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var cf_LiveProfile = Class.create();
2+
cf_LiveProfile.prototype = Object.extendsObject(AbstractAjaxProcessor, {
3+
/*
4+
* Retrieves the user photo from the Live Profile, if possible, otherwise
5+
* gets the photo from the user record if possible.
6+
*
7+
* Returns the path to the photo or an empty string
8+
*/
9+
getPhoto: function(){
10+
// Get the Sys ID of the user that we're retrieving the photo for
11+
var user_id = this.getParameter('sysparm_user_id');
12+
gs.log("getPhoto called for: " + user_id, "cf_LiveProfile");
13+
var photo_path;
14+
15+
// Query for the live profile record
16+
var live_profile_gr = new GlideRecord('live_profile');
17+
live_profile_gr.addQuery('document', user_id);
18+
live_profile_gr.query();
19+
if(live_profile_gr.next()) {
20+
if(live_profile_gr.photo.getDisplayValue()){
21+
photo_path = live_profile_gr.photo.getDisplayValue();
22+
gs.log("Retrieved photo from live profile: " + photo_path, "cf_LiveProfile");
23+
24+
}
25+
}
26+
// Check to see if we have a photo from the profile
27+
if(!photo_path){
28+
// No profile photo found, query for the user photo
29+
var user_gr = new GlideRecord('sys_user');
30+
user_gr.addQuery('sys_id', user_id);
31+
user_gr.query();
32+
if(user_gr.next()) {
33+
photo_path = user_gr.photo.getDisplayValue();
34+
gs.log("Retrieved photo from user record: " + photo_path, "cf_LiveProfile");
35+
} else {
36+
photo_path = '';
37+
gs.log("No photo found", "cf_LiveProfile");
38+
}
39+
}
40+
return photo_path;
41+
},
42+
43+
type: 'cf_LiveProfile'
44+
});

0 commit comments

Comments
 (0)