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 / Changing Gallery Items...
Power Apps
Answered

Changing Gallery Items - Runtime

(0) ShareShare
ReportReport
Posted on by 27

Hello everyone! I hope you guys are doing great!

 

I have an app with some databases and I would like to change the items from gallery based on user login. I designed my users table so that I can define for each user which base they can connect to.

 

In short, based on the user "bases" column (from user table), I need to switch the database showed in the gallery. Is there any smart way to make this possible?

 

Thanks in advance!

Categories:
I have the same question (0)
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Jerfsousa 

    Why not just use a single table, add a column for the user and filter it at the time of login?

  • Jerfsousa Profile Picture
    27 on at

    Thanks @Drrickryp it works very well!

     

    I've set my list from sharepoint (almost 8000 records), then I've created a collection in order to make possible to read all the lines... and it works! The code that I used is below.

     

    ClearCollect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=1 && ID1<=2000));;
    Collect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=2001 && ID1<=4000));;
    Collect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=4001 && ID1<=6000));;
    Collect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=6001 && ID1<=8000))

     

    I am using the collection on gallery and I am not using Forms... I set some text inputs and a button to save change, where I am using Patch to record the data... 

     

    Patch(
     baseItensAlternativos;
     LookUp(
     baseItensAlternativos;
     ID1 = Galeria.Selected.ID1
     );
     {
     Status : radioStatus.Selected.Value;
     PartNumber: txtPartNumber.Text;
     DescricaoItem: txtDescricao.Text;
     FabricanteAtual:txtFabAtual.Text;
     'Frota ':txtFrota.Text;
     FabricanteAlternativo:txtFabAltern.Text;
     FornecedorAlternativo: txtFornAltern.Text;
     Comentarios: txtComentarios.Text
     }
    )

     

    My problem now is: It is running everything well, but my sharepoint list is not being affected, when the user saves the changes, what is being affected is my collection only! How should I proceed to affect my sharepoint list instead collection?

  • Gochix Profile Picture
    1,937 Moderator on at

    Hi @Jerfsousa ,

     

    That's because you are patching the collection not the SharePoint list.

     

    Patch(
     BaseCompletaItensAlternativos;
     LookUp(
     baseItensAlternativos;
     ID1 = Galeria.Selected.ID1
     );
     {
     Status : radioStatus.Selected.Value;
     PartNumber: txtPartNumber.Text;
     DescricaoItem: txtDescricao.Text;
     FabricanteAtual:txtFabAtual.Text;
     'Frota ':txtFrota.Text;
     FabricanteAlternativo:txtFabAltern.Text;
     FornecedorAlternativo: txtFornAltern.Text;
     Comentarios: txtComentarios.Text
     }
    )
    
    ClearCollect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=1 && ID1<=2000));;
    Collect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=2001 && ID1<=4000));;
    Collect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=4001 && ID1<=6000));;
    Collect(baseItensAlternativos;Filter(BaseCompletaItensAlternativos;ID1>=6001 && ID1<=8000))
  • Jerfsousa Profile Picture
    27 on at

    Hey @Gochix , thanks for the support,

     

    Let me see if I got you correctly…

     

    I must patch the Sharepoint list instead collection, right? 

    What about my gallery? I presume that If I patch sharepoint list my Gallery will be out of date… it will cause a misalignment between sharepoint list and my gallery! 

    If this is the way, is it a good practice to rebuild the collection like you mentioned in ur answer? 

  • Verified answer
    Gochix Profile Picture
    1,937 Moderator on at

    Hi @Jerfsousa ,

     

    Correct. You should patch the SharePoint list instead of collection if you should update the data and later use it to display.

    You have a few options how to deal with the issue.

    1) Patch the collection and SharePoint list in the same time.

    2) Patch the SharePoint list and then Collect data again to collection after Patching.

     

    It all depends how frequently you are going to be patching the data. If this happens not very often and you only need to patch changes once in a while then you could just patch the sharepoint and then collect collection afterwards.

     

    I'm not very sure if this is the best practice or not. I'm sometimes using the same principle in my projects where the data load is similar to yours and never had any issues so far.

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Jerfsousa 

    You can use a form with the data source as your splist and set the Item property to LookUp(splist,ID=Galleria.Selected.ID). For the ID1 field in the form set the Update property to

    Coalesce(Parent.Default,First(Sort(splist, ID1, Descending)).ID1+1) and hide the card so users can't change it.

     Then in the OnSuccess property of the form, re-collect your collection.

    Replace splist in the formulas above with your actual list.

  • Jerfsousa Profile Picture
    27 on at

    I've made some tests and the best result was performing a double patch (list and collect). To be honest, I am not confident that is not the best way, but it will attend for now.

     

    Thanks so much for the attention @Drrickryp 

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 July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard