How can I pull the thumbnailphoto from Azure AD?

paul971
Mega Expert

need to pull in a profile photo for users from Azure AD to ServiceNow. 

 

How can this be done? Do we need to create a GraphAPI or can I somehow fetch them another way from Azure AD? converting them to base 64

1 REPLY 1

Mike Patel
Tera Sage

You can use get User Info activity that is under Azure AD and parse out "thumbnailphoto" attribute and use below code to convert photo. replace fields next to xxxxx.

  var sourcePhoto = workflow.scratchpad.xxxxxxxxx; 
   
    var sysDecodedAttachment = new GlideSysAttachment();  
    var DecodedBytes = GlideStringUtil.base64DecodeAsBytes(sourcePhoto);  
    var attID = sysDecodedAttachment.write(target, 'photo', 'image/jpeg', DecodedBytes);  
    var newAttachment = new GlideRecord("sys_attachment");  
    newAttachment.addQuery("sys_id", attID);  
    newAttachment.query();  
    if (newAttachment.next()) {  
        newAttachment.table_name = "ZZ_YYsys_user";  
        newAttachment.table_sys_id = user.sys_idxxxxxxxxxx;  
        newAttachment.content_type = 'image/jpeg';  
        newAttachment.update();  
    }