web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Creating a Collection ...
Power Apps
Answered

Creating a Collection from Office365Users.UserPhoto?

(0) ShareShare
ReportReport
Posted on by 15

Hi all,

 

I'm building my first powerapp, and I'm very happy with how it's going. In one portion of the app, I am listing employees from a sharepoint list (list than 100) and matching those to their photo with Office365Users.Userphoto(EmployeeTable.Email). This works, but there are some refresh problems in the list (gallery) as it appears to load the first photo as the default for each entry and then replaces it with the correct user photo. Sometimes this refresh is slightly delayed and leads to a poor user experience.

 

I figured I could possibly prevent this by loading photos into a collection, but I am running into a wall on this. Can a collection hold this photo data? Is there a better way to solve this refresh problem?

 

Thanks in advance for your help and input.

Jeff

Categories:
I have the same question (0)
  • Verified answer
    GarethPrisk Profile Picture
    2,828 on at

    Yes! We have attempted to solve this in the MSFT Team app samples.

    Basically, you can collect the images after they have been initially retrieved, and then reference them from the collection instead of the direct call. It's not a perfect pattern, and works best if you add the image column to your Gallery's collection (but also works as a lookup on a Gallery with a direct data call).

    You do not want to for a Collect/ForAll to get the images from the connector. I have found this approach to be very slow; given the non-batching nature of the request.

     

    In a nutshell

    • Using a triggering mechanism to collect the retrieved photos
      • OnHidden of the screen
      • After a code block
      • OnChange of a TextInput (maybe as a searching mechanism)
    • Collect the photos from the Image control of your Gallery
      • With the email reference and image
    • Have your Gallery check/use the local copy instead of re-retrieving the images each time

    Here is a sample of the OnHidden of a screen in one of our newer apps.

    ForAll(
     galLinksContacts_Contacts.AllItems,
     With(
     {
     varUserName: ThisRecord.lblGalLinksContacts_Contacts_Name.Text,
     varUserImage: ThisRecord.imgGalLinksContacts_Contacts_Image.Image
     },
     If(
     IsBlank(
     LookUp(
     colUserImages,
     tblUserName = varUserName
     )
     ),
     Collect(
     colUserImages,
     {
     tblUserName: varUserName,
     tblUserImage: varUserImage
     }
     )
     )
     )
    )
    

     

    Then the Image control in our Gallery has this for its Image property.

    IfError(
     With(
     {varUserName: ThisItem.Email},
     With(
     {
     varUserImage: LookUp(
     colUserImages,
     tblUserName = varUserName,
     tblUserImage
     )
     },
     If(
     IsBlankOrError(varUserImage),
     If(
     IsBlankOrError(varUserName),
     Image_DefaultUser,
     Office365Users.UserPhotoV2(varUserName)
     ),
     varUserImage
     )
     )
     ),
     Image_DefaultUser
    )

    This cuts down on requests significantly, especially with multiple to/from navigation occurring. This allows the retrieved image to be reused within the app as well.

    You can and will see it stutter, but this is mostly due to the LookUp happening after the Gallery has been refreshed. You could AddColumn if you were using a local collection and store the image in the collection row, to alleviate this, however.

  • jkoertzen Profile Picture
    15 on at

    Thanks @GarethPrisk. I haven't had a chance to try that yet, but I wanted to acknowledge your reply. It looks promising.

  • jkoertzen Profile Picture
    15 on at

    Hey @GarethPrisk ... Thanks!

     

    I've implemented it, and it works great. I still have a minor glitch, though. I do have the image displayed in the gallery, and when it loads, it loads the first photo and applies that as the default image to each record before it then updates with the Office365 photo lookup. If I navigate away from the page too quickly (before it's had a chance to process the photo update for each entry), that first photo is then applied to the collection as the image for the majority of the staff.

     

    I'm still toying around to see if I can fix this little glitch. But overall, the method is great! 

  • jkoertzen Profile Picture
    15 on at

    Solved! Since my list is very small (<100), I moved the load to app start. The data load for the employees comes from a Sharepoint list we had previously created and maintained with a list of employees, so it keeps it small. Instead of using the gallery as the source in the ForAll loop, I use this sharepoint list. In the ForAll, I use the office365 lookup as the img variable. This works perfectly. No stutter. Every image loads quickly and accurately.

    Thank you!

    ForAll(
     'Sharepoint List',
     With(
     {
     varUserName: ThisRecord.Email,
     varUserImage: Office365Users.UserPhoto(ThisRecord.Email)
     },
     If(
     IsBlank(
     LookUp(
     colUserImages,
     tblUserName = varUserName
     )
     ),
     Collect(
     colUserImages,
     {
     tblUserName: varUserName,
     tblUserImage: varUserImage
     }
     )
     )
     )
    )

     

    One small note is that for some reason the UserPhotoV2 isn't working in our environment, but UserPhoto does.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard