SOLVED

PowerApps Profile Pic IF statement

Copper Contributor

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

5 Replies
best response confirmed by PerfPC (Copper Contributor)
Solution

@PerfPC 

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

 

 

Snag_a23e3ab.png

 

To use the sample image use:

 

If(
    Office365Users.UserPhotoMetadata(Gallery1.Selected.Mail).HasPhoto,
    Office365Users.UserPhoto(Gallery1.Selected.Mail),
    SampleImage
)

 

 

Hope this helps.

 

Ellis

@ekarim
Perfect, thank you so much, seeing what you have in the code I certainly did blind myself.
Really appreciate your input.

Many Thanks
Cecil

@ekarim

 

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

 

@PerfPC 

Try the following:

 

If(
    Office365Users.UserPhotoMetadata(ThisItem.Mail).HasPhoto,
    Office365Users.UserPhotoV2(ThisItem.Mail),
    SampleImage
)

 

 

Runtime output example - within a Gallery:

Snag_286384f.png

Note that ThisItem.UserPrincipalName and ThisItem.Id seem to also work.

 

Snag_2c33e81.png

 

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#M8...

 

However,  I do see a warning when I am editing the code, although the photos are being shown correctly:

Snag_2be07f8.png

 

See the following post Office365Users Connector – Get rid of this warning!

https://thepoweraddict.com/office365users-connector-get-rid-of-this-warning/

 

Ellis

Thanks appreciate your input, I'll work through what you have suggested above.
1 best response

Accepted Solutions
best response confirmed by PerfPC (Copper Contributor)
Solution

@PerfPC 

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

 

 

Snag_a23e3ab.png

 

To use the sample image use:

 

If(
    Office365Users.UserPhotoMetadata(Gallery1.Selected.Mail).HasPhoto,
    Office365Users.UserPhoto(Gallery1.Selected.Mail),
    SampleImage
)

 

 

Hope this helps.

 

Ellis

View solution in original post