Forum Discussion
PowerApps Profile Pic IF statement
- Feb 18, 2022
Office365Users.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
Office365Users.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
- PerfPCFeb 18, 2022Copper Contributorekarim
Perfect, thank you so much, seeing what you have in the code I certainly did blind myself.
Really appreciate your input.
Many Thanks
Cecil- PerfPCFeb 21, 2022Copper Contributor
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
- ekarimFeb 21, 2022Brass Contributor
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:
https://powerusers.microsoft.com/t5/Building-Power-Apps/UserPhotoMetaData-UserID-Error/m-p/295317/highlight/true#M85146
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