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

Delete / Clear / Update Local Collection

My Scenario is this:

 

1) Open form (check)

2) Load local data that has been stored on device from previous session (check) LoadData(LocalSubmit,"LocalSubmit")

3) gallery that displays loaded data has a button to clear/delete local data (this data is for backup purposes only for the just in case scenarios where the user can restore the collection) I do this using RemoveIf(LocalSubmit,true). It does clear the selection however if i exit the app and return the records are still there. I have also tried Clear(LocalSubmit) with the same results.

 

So how do you permantely clear local collections?

 

The other question i have is how do you edit local collections with multi forms / screens? I have tried everything that i can think of and no luck. Does anyone have any experience?

 

this is the code i have to create the collection which works i have tried getting the current record with ThisItem  ,  Parent  , but im obviously missing something. 

 

Collect(Local,Patch(
EditForm1.Updates,EditForm1_1.Updates,EditForm1_2.Updates,EditForm1_3.Updates,EditForm1_4.Updates,EditForm1_5.Updates,EditForm1_6.Updates))

Thanks in advance

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

thanks for your assistance. maybe the weekend cleared my head. this is what i did to get it working.

 

Patch(LocalConnection,ThisItem,
EditForm1.Updates,EditForm1_1.Updates,EditForm1_2.Updates,EditForm1_3.Updates,EditForm1_4.Updates,EditForm1_5.Updates,EditForm1_6.Updates)

I didnt realize that Patch could update as well as create.

 

View solution in original post

9 REPLIES 9
Sienna
Level 10

Re: Delete / Clear / Update Local Collection

Hi

Collection is automaticaly cleared when the app is closed. However when you have the colection saved by SaveData() then it will come automatically back by trigering LoadData() function. If you want the changes to be permanent in saved collection then you will have to save it with SaveData() function after every clear, update, collect etc... It is not very clear what are you using the collection for and what the collection is for in your app so if you need more help then you will have to give us more information

ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

Hi Sienna,

 

 Thanks for the response. Basically what i am doing is developing an app for offline use. the thing is that everything is going to be local until the user when connected submits to SharePoint list.

 

So after clearing the collection i have to save it to keep it clear. that makes sense. seems so simple and sorry still lots to learn.

 

Now if only i can get a record in the local collection to update i will 99% of the way there.

ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

I guess i should ask, what are the limitations of storing data in the local collection? How long will it stay there?

 

a little more background i keep a record of records that were submitted and deleted. for backup purposes really. rule number one of digital data collection. dont lose anything. and from what i have been reading its very easy for a submission to fail (lack of connectivity) and have the record go into the nether.

Sienna
Level 10

Re: Delete / Clear / Update Local Collection

As far as I understand you correctly... I don't think you have to save the collection or load it.. Don't even use the save and load function which is completely useless in your scenario. The collection is saved and ready to use after every update or change you make while the app is running. When the app is terminated then all data from the collection are cleared which is exactly what you need. There is no limit to the collection as far as I know and it will stay there until you terminate app. 

 

For adding row into collection use Collect function 

Collect(MyBeautifulCollectionName,{ID:1, Name:"Johny"})

For editing row in collection use Update() or UpdateIf() function

UpdateIf(MyBeautifulCollectionName, ID=1, {Name:"English"})

For deleting row from collection use Remove() or RemoveIf() function

RemoveIf(MyBeautifulCollectionName, ID=1)

 

You can find list of all function here

https://docs.microsoft.com/en-us/powerapps/formula-reference

 

ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

I do want to retain the local collection(s) so i will use the load and save but what you state makes perfect sense also, Thank - you. 

 

Yes i have tried UpdateIf with out success as i just dont know how to get the current record i am editing. I dont have an ID (can you create an autonumber ID within powerapps? as i have not yet submitted to SP.

 

is it possible to do something like this? 

UpdateIf(MyBeautifulCollectionName, ID=Current ID, {Patch(myform1,myform2...})

ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

UpdateIf(Local,Title="DataCardValue7",Patch(
EditForm1.Updates,EditForm1_1.Updates,EditForm1_2.Updates,EditForm1_3.Updates,EditForm1_4.Updates,EditForm1_5.Updates,EditForm1_6.Updates));SaveData(Local,"Local");Navigate
(OutBox,ScreenTransition.Fade)

it appears that this code works. thank you for steering me in the right direction. I need to tweak a few things but i think i got it. 

Highlighted
ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

i spoke to soon. works fine with one record in the collection but not multiple if that makes sense.

 

added a new record and saved.

Edit that record and appears to update my changes.

add new record and save

edit previous record and updates are no longer there

 

I will experiment more. 

Sienna
Level 10

Re: Delete / Clear / Update Local Collection

I only gave you an example of the columns in the collection. You don't need to have an id column but you will need a unique value in the row so it will change only one row or the row you wish. Lets say your collection "MyBeautifulCollection" will have structure like this

 

FirsName       Surname          Age 

Peter              Wood                   20

John               Callum                 10

Sylvia             Oz                        12

Sylvia             Flower                  15

 

Now if you want to change Silvia Oz age to 16. You have to specify which row you want to update so by

UpdateIf(MyBeautifulCollection, FirstName="Sylvia", {Age:16})

both Sylvia will have their age changed to 16 because there are 2 Sylvia in FirsName column. Therefore I always use unique ID in my collection so I don't get duplicate. In this example to change only Sylvia Oz name you will have to specify more column in UpdateIf

UpdateIf(MyBeautifulCollection, FirstName="Sylvia" && Surname= "Oz", {Age:16})

 

Hope it gives you a sence and kicks you a step further 🙂

 

 

To patch collection into sharepoint I would recommend you to create new question because I have never worked with sharepoint

ldurland
Level: Powered On

Re: Delete / Clear / Update Local Collection

thanks for your assistance. maybe the weekend cleared my head. this is what i did to get it working.

 

Patch(LocalConnection,ThisItem,
EditForm1.Updates,EditForm1_1.Updates,EditForm1_2.Updates,EditForm1_3.Updates,EditForm1_4.Updates,EditForm1_5.Updates,EditForm1_6.Updates)

I didnt realize that Patch could update as well as create.

 

View solution in original post

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 (Last 30 Days)
Users online (5,040)