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 / Saving and retrieving ...
Power Apps
Answered

Saving and retrieving a collection when PowerApps/Browser closes

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello All,

 

I have an app that is basically a questionnaire. The app is connected to an SQL back-end. On starting the app, I create a collection of the questions from the SQL table and the user can then respond to the questions, these Reponses are stored in the collection. At the end of all questions, I have a button which uses ForAll and Patch to write the collection back to another SQL table. A concern that's been raised is that, if the browser freezes or if there is an issue with the connection, then the user will need to restart the questionnaire again. Is there any way I can get around this? (e.g. save a collection, I did try exploring savedata and load data, but apparently those do not work on a browser). Any help will be extremely appreciated.

 

Thank you!

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

    @Anonymous 

    You are correct that savedata and loaddata do not work on a browser.  If you want "save-as-you-go" ability and your app will be used in a browser, then you will need to store the information in your datasource as you go instead of in a collection.  If you want separated data (i.e. pre-submitted and post-submitted) to follow your concept of having the items completed before submitting to the real datasource, then consider a temporary "working" table in your datasource that will hold that information.  You'll obviously want to make a column to identify the data to the user so that the information is only for that user.

     

    I hope this is helpful for you.

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @RandyHayes Thank you for the reply. 

    The reason why I'm not saving back to the data source after each question is because of the time it takes for powerapps to write back to SQL (I've read that powerapps needs to make a call to SQL and that takes time).

     

    Although I'm considering saving after each category of questions is answered. My app has 3 galleries. The first two galleries are for the category and sub-category, the user can select which category/sub-category they'd like the answer the questions for. The third gallery has the questions along with drop downs for user Reponses. I'd atleast like to save back to the data source when a user completes a category. However I'm unsure of what property to use within the gallery or elsewhere. Any ideas/suggestions will be helpful.

     

    Thanks Again!

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    There are a variety of ways to separate save-backs to the datasource to not impact performance.  In general, yes it takes a moment to save back, but it should be relatively quick.

     

    So if you have galleries with these items in, I would just use the same logic you have for saving when done can be applied - do you have that logic together now, or is that what you are asking about?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @RandyHayes I'm currently doing a save right at the end using a button. I'm using Forall and patch to save the data to the data source. I'd like some ideas on how to separate the save backs. I'll probably use the same code i.e.

    Forall and patch to write back to the data source, but need some advice on how to separate it. For example I was exploring trying to save back once an item in the first gallery changes. However I did notice there is no Onchange property for a gallery. Any advice on how can I separate the save backs?

     

    Thanks!

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    This would be a great place for an EditForm as it has an Unsaved property and handles all the save for you.

    However, if you are going with a Gallery, there are some ways to go about this.  One of my favorites is a string comparison.  Typically I will create a label that has a string built from all of the values concatenated together from the controls in the gallery.  At the same time, I will take the original record for the whole gallery and create the same exact string based on the record.  Then it's any easy job to just compare the two.  The label for the gallery values will change dynamically based on any changes in the gallery, so once a change is made, then the strings will not compare.

    Example, let's say we have a gallery for section 1 with a dropdown in it (Dropdown1) for projects.  And we have a data record for section 1 with the following records:

       [{Question: 1, Answer: "ProjectA"}, {Question: 2, Answer: "ProjectB"}, {Question: 3, Answer: "ProjectC"}]

    I would have a label on the screen (usually hidden), we'll call it lblGalVals.  It has a Text property of:

        Concat(Gallery1.AllItems, Dropdown1.Selected.Value)

    Optionally we could have another label with the underlying record put together (I say optionally because this can be done elsewhere).  Let's call it lblRecVals and its text property would be:

        Concat(section1Records, Answer)

     

    Initially your Gallery would display the record values (not going to get into setting the default properties here, but that is what would be needed).  So, the lblGalVals would show : ProjectAProjectBProjectC and the lblRecVals would show : ProjectAProjectBProjectC

    Now, I can use a Toggle control and set its default property to !(lblGalVals.Text = lblRecVals.Text)

    This Toggle would be true when there are changes and false if not.

    If someone changes a dropdown in the gallery, the lblGalVals text will change and thus the Toggle will go true (on).

    You can then simply check the Toggle to see if it is true to determine if you need to write back to the datasource.

     

    I hope that is relatively clear.

     

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 358 Most Valuable Professional

#2
11manish Profile Picture

11manish 214 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard