cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Jerfsousa
Frequent Visitor

Changing Gallery Items - Runtime

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!

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

7 REPLIES 7
Drrickryp
Super User
Super User

@Jerfsousa 

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

Jerfsousa
Frequent Visitor

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?

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

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? 

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
Super User
Super User

@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
Frequent Visitor

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 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,274)