|
| 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