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

Display a gallery based on user (conditional gallery display)

I am building a powerapp to keep track of all the devices my team uses for our internal testing and it will keep track of who currently has the device in their possession; sort of like a library database for our devices. I am adding a gallery to display all the devices a user currently has "checked out".

 

I have the following code which correctly displays which user has what devices in their possesion:

Filter(
    'Asset Tracker',
    Owner = User().FullName
)

I want to display a message that informs the user if they do not have any devices "checked out" currently. I cannot get it display anything with the few attempts I have made at if/switch statements.

 

Has anyone done something similar with conditional gallery formatting that could help get the display to work properly?

 

I am using a sharepoint list.

 

Thanks for any input you can provide.

1 ACCEPTED SOLUTION

Accepted Solutions
R3dKap
Level 10

Re: Display a gallery based on user (conditional gallery display)

Hi @gpedone,

Here is my suggestion to your problem:

  • add a label lblNoDevices with the text "You have no devices checked out" in front of your gallery
  • set its Visible property to IsEmpty(YourGallery.AllItems)
  • set your gallery Visible property to Not(lblNoDevices.Visible)

Would this solution suit you ?

Emmanuel

View solution in original post

8 REPLIES 8
R3dKap
Level 10

Re: Display a gallery based on user (conditional gallery display)

Hi @gpedone,

Here is my suggestion to your problem:

  • add a label lblNoDevices with the text "You have no devices checked out" in front of your gallery
  • set its Visible property to IsEmpty(YourGallery.AllItems)
  • set your gallery Visible property to Not(lblNoDevices.Visible)

Would this solution suit you ?

Emmanuel

View solution in original post

Super User
Super User

Re: Display a gallery based on user (conditional gallery display)

I would also suggest that you set a variable to the user's name in the OnStart or OnVisible of the first screen. Then use the variable in the Filter. This will make your filter formula delegable and a little faster because User() has to execute for every row that the filter condition is being applied to.

 

Example: 

Setting the Variable: Set(gvUserFullName, User().FullName)

Filter Formula: Filter('Asset Tracker', Owner = gvUserFullName)



--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.
Community Support Team
Community Support Team

Re: Display a gallery based on user (conditional gallery display)

Hi @gpedone ,

Could you please share a bit more about your scenario?

Do you want to display a prompt info "You do not have any devices "checked out" currently" when the user does not have any devices checked out?

 

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

Add a Label control within your app, set the Text property to following:

"You do not have any devices "checked out" currently"

set the Color property to following:

RGBA(255, 0, 0, 1)

set the Visible property of this Label to following:

If(
    IsEmpty(Filter('Asset Tracker', Owner = User().FullName)),
true,
false )

 

Set the Items property of the Gallery to following formula:

Filter('Asset Tracker', Owner = User().FullName)

set the Visible property to following formula:

If(
!IsEmpty(Filter('Asset Tracker', Owner = User().FullName)),
true,
false
)

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

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.
gpedone
Level: Powered On

Re: Display a gallery based on user (conditional gallery display)

Thank you this worked and was a simple solution

Tahina
Level: Powered On

Re: Display a gallery based on user (conditional gallery display)

Hi all,

 

I have the same problem with my application. I would like to display Gallery items based on filter condition.

Only items which concern CURRENT USER should be displayed in my application. So I have set a variable (varUser) in my OnStart control of my application.  And in my items gallery control, I call this variable to check if in my gallery there is any items created by current user.  IT DOESN'T WORK FOR THE MOMENT.

 

SortByColumns(
    Filter(
        [@'Leave Request'];
        StartsWith(
            Title;
            TextSearchBox1.Text
        ); Demandeur = varUser
    );
    "Title";
    If(
        SortDescending1;
        Descending;
        Ascending
    )
)

 

appleaverequest.png

 

 

 

 

 

Anyone could help me how to make  it work ?

 

Thanks in advance.

R3dKap
Level 10

Re: Display a gallery based on user (conditional gallery display)

Hi @Tahina,

You cannot compare users by doing:

Demandeur = varUser

You have to compare one of their properties, like the email:

Demandeur.email = varUser.email

Hope this helps,

Emmanuel

Tahina
Level: Powered On

Re: Display a gallery based on user (conditional gallery display)

Hi @R3dKap ,

 

Thanks for your help.

It works.

What I have made is that  in "Onvisible" property of my Gallery, I have set variable like Set(CurrentUser; User().Email), and then I compare the properties in my gallery items :

Demandeur.Email= CurrentUser

 

Nice day !

 

 

Highlighted
R3dKap
Level 10

Re: Display a gallery based on user (conditional gallery display)

Glad it works... See you...

Emmanuel

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps 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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,752)