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

Help working with a collection

Hello guys, I need some help working with a collection.

 

I have a sharepoint list with 600-700 records now, I want to use the Date filter on a gallery based on a collection.

 

So I set the OnStart to Collect, and then when a record is submitted, I clear it and do it again, and also when the records is edited.

*Please tell me if there is a better way to do this!

 

I have a doubt on how to erase the record from the original data source and also the collection, I tried to do the Remove function on a gallery but it asks from the source that is not the original anymore...

 


Accepted Solutions
KroonOfficeSol
Level 10

Re: Help working with a collection

@AleChoski,

 

You're question is on the wrong board and very faque in what you want to achieve, I think that's the reason you didn't get a good reaction yet. But I will try to answer you're question.

 

First it's not really clear why you collect your sharepoint list, but I persume it's a performance think, is it? Therefore it's not smart you re-collect you're data every time for the same reason, but if you want to do this just use the ClearCollect() formula. This will first empty the collection and then re-collect the datasource by default. In the ClearCollect() second parameter you use the Filter(datasource, date = datevalue), to collect the right data. Place this on the OnStart is not the best place, there you want to do this several times. Add the end off my reaction I will come back to this.

 

Keep in mind that you should think about delegation, because else not more then 500 (max 2000) records will be load in and evaluated! Basically this means that when you're sharepoint list will exceed max 2000 rows the app will break. I don't know if filtering on the date is delegatable, if not then don't use a collection.

 

Using the remove function is the right move, but then you have to split this up in 2-3 formula's. In suggest to first store an unique identifier from the record (like the ID) in a local variable en then use the Remove() formula with in the second part a LookUp() formula. Like this:

UpdateContext({MyVariable: Gallery.Selected.ID});
Remove(MyCollection, LookUp(MyCollection, ID = MyVariable));
Remove(SharePointList, LookUp(SharePointList, ID = MyVariable))

The LookUp will direct SharePoint to the right record to delete.

 

To add a new record you can use two formula's Collect() and Patch(). They work like this:

Collect(MyCollection, {Parameter1:Value, Parameter2:Value})
Collect(MySharePointList, {Parameter1:Value, Parameter2:Value})

or

Patch(MyCollection, Default(MyCollection), {Parameter1:Value, Parameter2:Value})
Patch(MySharePointList, Default(MySharePointList), {Parameter1:Value, Parameter2:Value})

Collect will automaticly take the default normally, but Patch is maybe more reliable I think. 

To Change a record you use the patch function:

Patch(MySharePointList, LookUp(MySharePointList, ID = MyVariable), {Parameter1:Value, Parameter2:Value})

You notice that I don't add the Patch for the collection, because how to do this is based on the way you want to update. Using a Form you can simply use a SubmitForm(MyForm) and the form will handle the update in the collection (assuming that the form is connected to the collection). If you want inline editing in the Gallery you use the patch function on a button/icon. You here can reference the selectedItem like:

 

Patch(MyCollection, ThisItem, {P1:Value, P2:Value, etc})

 ThisItem works better and faster than referencing the Gallery.Selected.

 

Also when you use the formula's at more then one place, like with the ClearCollect(MyCollection, MySharePointList), then I think it's better not to place this formula's under the OnStart event. Better is it to use Events (so I name them) which you can tricker from different places in you're app. Basically you centralize the formula()/Logic making it easier to manage/adjust when needed. T

 

he first time you tricker this event is in the OnVisible at the first screen, using a variable to make it only run on the start off your app. On YouTube a posted a video on how to make events and use them, maybe you want to check this out:

 

https://www.youtube.com/watch?v=jlN6wzFp6Fg&list=PL2zsZutKZiTPBnHR1-NnqewollxBfpqbE&index=14

 


All Replies
KroonOfficeSol
Level 10

Re: Help working with a collection

@AleChoski,

 

You're question is on the wrong board and very faque in what you want to achieve, I think that's the reason you didn't get a good reaction yet. But I will try to answer you're question.

 

First it's not really clear why you collect your sharepoint list, but I persume it's a performance think, is it? Therefore it's not smart you re-collect you're data every time for the same reason, but if you want to do this just use the ClearCollect() formula. This will first empty the collection and then re-collect the datasource by default. In the ClearCollect() second parameter you use the Filter(datasource, date = datevalue), to collect the right data. Place this on the OnStart is not the best place, there you want to do this several times. Add the end off my reaction I will come back to this.

 

Keep in mind that you should think about delegation, because else not more then 500 (max 2000) records will be load in and evaluated! Basically this means that when you're sharepoint list will exceed max 2000 rows the app will break. I don't know if filtering on the date is delegatable, if not then don't use a collection.

 

Using the remove function is the right move, but then you have to split this up in 2-3 formula's. In suggest to first store an unique identifier from the record (like the ID) in a local variable en then use the Remove() formula with in the second part a LookUp() formula. Like this:

UpdateContext({MyVariable: Gallery.Selected.ID});
Remove(MyCollection, LookUp(MyCollection, ID = MyVariable));
Remove(SharePointList, LookUp(SharePointList, ID = MyVariable))

The LookUp will direct SharePoint to the right record to delete.

 

To add a new record you can use two formula's Collect() and Patch(). They work like this:

Collect(MyCollection, {Parameter1:Value, Parameter2:Value})
Collect(MySharePointList, {Parameter1:Value, Parameter2:Value})

or

Patch(MyCollection, Default(MyCollection), {Parameter1:Value, Parameter2:Value})
Patch(MySharePointList, Default(MySharePointList), {Parameter1:Value, Parameter2:Value})

Collect will automaticly take the default normally, but Patch is maybe more reliable I think. 

To Change a record you use the patch function:

Patch(MySharePointList, LookUp(MySharePointList, ID = MyVariable), {Parameter1:Value, Parameter2:Value})

You notice that I don't add the Patch for the collection, because how to do this is based on the way you want to update. Using a Form you can simply use a SubmitForm(MyForm) and the form will handle the update in the collection (assuming that the form is connected to the collection). If you want inline editing in the Gallery you use the patch function on a button/icon. You here can reference the selectedItem like:

 

Patch(MyCollection, ThisItem, {P1:Value, P2:Value, etc})

 ThisItem works better and faster than referencing the Gallery.Selected.

 

Also when you use the formula's at more then one place, like with the ClearCollect(MyCollection, MySharePointList), then I think it's better not to place this formula's under the OnStart event. Better is it to use Events (so I name them) which you can tricker from different places in you're app. Basically you centralize the formula()/Logic making it easier to manage/adjust when needed. T

 

he first time you tricker this event is in the OnVisible at the first screen, using a variable to make it only run on the start off your app. On YouTube a posted a video on how to make events and use them, maybe you want to check this out:

 

https://www.youtube.com/watch?v=jlN6wzFp6Fg&list=PL2zsZutKZiTPBnHR1-NnqewollxBfpqbE&index=14