Feb 17 2022 02:08 PM
Hi All,
I've currently got a SP list with a people field showing the users profile picture. In PowerApps I've a gallery to display all my columns including the profile picture with the below code. (Picture= column for my picture)
Office365Users.UserPhoto(ThisItem.Picture.Email)
This works perfectly fine apart from any users who don't have a profile picture set, I'd like to set an IF statement to display a specific picture i.e. SampleImage if the user doesn't have a picture.
I've checked many methods, scouring and searching and can't seem to get this to work, got to be really simple yet i think I've blinded myself with the attempts.
Any support on this would be great and appreciated.
Thanks
Cecil
Feb 18 2022 02:14 PM - edited Feb 18 2022 02:20 PM
SolutionOffice365Users.UserPhotoMetadata().HasPhoto
will return true or false. You can use this in an If condition:
If(
Office365Users.UserPhotoMetadata(Gallery1.Selected.Mail).HasPhoto,
Office365Users.UserPhoto(Gallery1.Selected.Mail),
'robot-face'
)
To use the sample image use:
If(
Office365Users.UserPhotoMetadata(Gallery1.Selected.Mail).HasPhoto,
Office365Users.UserPhoto(Gallery1.Selected.Mail),
SampleImage
)
Hope this helps.
Ellis
Feb 18 2022 03:43 PM
Feb 21 2022 02:12 PM
Just noticed when running the App I get the error in the attached image.
The exact code I used was derived from your information below, the image of the user and the default image shows fine but with the error. Any ideas what this could be or a possible fix.
If(
Office365Users.UserPhotoMetadata(ThisItem.Picture.Email).HasPhoto,
Office365Users.UserPhoto(ThisItem.Picture.Email),
'My-Default-Image'
)
Many Thanks
Cecil
Feb 21 2022 03:30 PM - edited Feb 21 2022 04:36 PM
Try the following:
If(
Office365Users.UserPhotoMetadata(ThisItem.Mail).HasPhoto,
Office365Users.UserPhotoV2(ThisItem.Mail),
SampleImage
)
Runtime output example - within a Gallery:
Note that ThisItem.UserPrincipalName and ThisItem.Id seem to also work.
Please see the following, which provides a different expression - if this is of benefit to your app:
However, I do see a warning when I am editing the code, although the photos are being shown correctly:
See the following post Office365Users Connector – Get rid of this warning!
https://thepoweraddict.com/office365users-connector-get-rid-of-this-warning/
Ellis
Feb 22 2022 12:31 PM
Feb 18 2022 02:14 PM - edited Feb 18 2022 02:20 PM
SolutionOffice365Users.UserPhotoMetadata().HasPhoto
will return true or false. You can use this in an If condition:
If(
Office365Users.UserPhotoMetadata(Gallery1.Selected.Mail).HasPhoto,
Office365Users.UserPhoto(Gallery1.Selected.Mail),
'robot-face'
)
To use the sample image use:
If(
Office365Users.UserPhotoMetadata(Gallery1.Selected.Mail).HasPhoto,
Office365Users.UserPhoto(Gallery1.Selected.Mail),
SampleImage
)
Hope this helps.
Ellis