cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tuuman
Level: Powered On

Using images from media in gallery view

Hi!

 

We have created an app that shows every contact information of employees or our organization. We have created a gallery view that displays contacts names, phonenumber, address and an image of the person. Originally this image was picked from Office 365 data but we noticed some lag with loading the image when the app was in use. While not completely unusable we started seeking better way to load the images.

 

So what we have done so far is that we have uploaded some images to the Powerapps media. Next we tried to add an image to one contact using simple If-statement in the gallerys Image section:

If(DisplayName="Person Name1";'Person Name1';'Default Image')

NOTE: The image files are named after the employee as Firstname Lastname format.

This worked fine. However since we have many employees using If-statement or Switch-statement can cause a huge block of code:

Switch(DisplayName;
     "Person Name1";'Person Name1';
     "Person Name2";'Person Name2';
     "Person Name3";'Person Name3';
     ........and so on till we get to the end and we can declare the default value
     'Default Image'
)

Now imaging if we have to do this for +80 personnel that is changing constantly. There's no way we can keep tracking what changes we have to do and changing the code isn't really a best practice.

Is there any easier way to get the image without using Office 365 data? We haven't been able to set the name from DisplayName in side ' '. And this is pretty much causing a lot of headache to us since we have to use ' ' to tell the app to use the image. If we only could put DisplayName inside ' ' somehow.

3 REPLIES 3
Community Support Team
Community Support Team

Re: Using images from media in gallery view

Hi @tuuman,

Could you please share a bit more about your scenario?

Do you want to display profile picture for the Employees of your Org in the Gallery using Media files in your app without using Office 365 data?

Based on the needs that you mentioned, I afraid that there is no direct way to achieve your needs in PowerApps currently.

As an alternative solution, you could consider take a try to save the Media Image files and corresponding Employee Name (DisplayName) into a Collection, then within the Gallery, you could use LookUp function to retrieve the corresponding image based on DisplayName of each employee.

I have made a test on my side, please take a try with the following workaround:9.JPG

 

10.JPG

Set the OnStart proeprty of the first screen of my app to following:

ClearCollect(
    EmployeeImages,
    {DisplayName: "Barry Cao", Image: 'Barry Cao'},
    {DisplayName: "charlie Liao", Image: 'charlie Liao'},
    {DisplayName: "dan he", Image: 'dan he'},
    {DisplayName: "Test2", Image: Test2},
    {DisplayName: "Kris Dai", Image: 'Kris Dai'}
)

On your side, you should type:

ClearCollect(
          EmployeeImages;
          {PersonName: "Person Name1"; Image: 'Person Name1'};
          {PersonName: "Person Name2"; Image: 'Person Name2'};
          {PersonName: "Person Name3"; Image: 'Person Name3'};
          ...
)

Set the Items property of the Gallery to following:

Office365Users.SearchUser()

Within the Gallery, set the Image property of the Image control to following:

If(
!IsBlank(LookUp(EmployeeImages, DisplayName = ThisItem.DisplayName, Image)),
LookUp(EmployeeImages, DisplayName = ThisItem.DisplayName, Image),
SampleImage
)

On your side, you should type:

If(
!IsBlank(LookUp(EmployeeImages, PersonName = ThisItem.DisplayName, Image)),
LookUp(EmployeeImages, PersonName = ThisItem.DisplayName, Image),
'Default Image'
)

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
tuuman
Level: Powered On

Re: Using images from media in gallery view

Thank you for your reply @v-xida-msft

 

Our original intend was to save images in media files and then call them in the gallery with certain names. What we thought we could do was to get ThisItem.DisplayName and inject that inside ' ' since the gallery image section required the usage of those single quotes. The problem is though if we put ThisItem.DisplayName inside ' ' Powerapps reads it as a file name and not as function call. If we put ThisItem.DisplayName without ' ' Powerapps reads it as a function but doesn't print image since DisplayName doesn't hold any. If we could somehow inject DisplayName inside ' ' we could achieve a much cleaner code that would automatically find corresponding image without the need of writing a new line of code. All what would left for us to is upload new image to the media.

 

Regarding to your workaround: Very interesting idea but ultimately it doesn't solve our problem. We still need to put huge amount code just to get collection. It would though clean up the code from the Gallery, but we could achieve same result with even less code by using Switch.

 

So ultimately what we want:

We want to get images without using Office 365 profile images. Therefore we added images to the mediafiles. We also want to make the code as short as possible by picking up name from DisplayName and search for corresponding image from media files. Only way we have succeed with this so far is creating If- and Switch-statements. Problem with these are they would be huge and end up being messy in the code. Creating collection would clean up the code from Gallery Image section but ultimately we still would have to manually input every item in the collection, making it huge and messy.

 

I hope this cleared a bit our situation.

tuuman
Level: Powered On

Re: Using images from media in gallery view

I'm not marking solutions to this thread since I haven't received any solutions.

We decided to do workaround and just create bunch of Switch cases. It's not the prettiest or the most practical but it works the way we basicly want it. We're still open for other suggestions.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 471 members 6,183 guests
Please welcome our newest community members: