cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ck25415
Level 8

Autosave with timer control with loop enabled

Hello,

 

I have screen1, screen2. I have a timer control on screen2 set to 60 seconds with repeat turned on. Ontimer end is set to Patch('datasource', Defaults('datsource'), EditForm1.Updates, EditForm2.Updates) and I also have a submit button on screen2 which kicks of a flow and also submits the item to sharepoint using the same patch function. Since trepeat is turned on, I see multiple entries created in sharepoint list and also final submit creates on more entry. 

 

Is it possible to save everything in one sharepoint list item without multiple entries?

 

Thanks,

1 ACCEPTED SOLUTION

Accepted Solutions
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Autosave with timer control with loop enabled

When you have `Defaults(datasourcename)` as the second parameter of the Patch function, it will always create a new record - which is why you're seeing many new records in your list.

 

If you want to have only one record auto-submitted (via the timer), you can store the current record to be stored in a variable, whose initial value would be `Defaults(datasourcename)` - so that the first time it will create a new record. But afterwards, you need to have that record that was created, so you'll be updating that record instead of creating a new one.

 

For example, in the OnVisible property of the first screen you can have the following expression:

Set(currentRecord, Defaults(datasourcename))

In the timer end, you can patch the current record - and update the current record with the result of Patch.

Set(
    currentRecord,
    Patch(
        datasourcename,
        currentRecord,
        EditForm1.Updates,
        EditForm2.Updates))

 

5 REPLIES 5
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Autosave with timer control with loop enabled

When you have `Defaults(datasourcename)` as the second parameter of the Patch function, it will always create a new record - which is why you're seeing many new records in your list.

 

If you want to have only one record auto-submitted (via the timer), you can store the current record to be stored in a variable, whose initial value would be `Defaults(datasourcename)` - so that the first time it will create a new record. But afterwards, you need to have that record that was created, so you'll be updating that record instead of creating a new one.

 

For example, in the OnVisible property of the first screen you can have the following expression:

Set(currentRecord, Defaults(datasourcename))

In the timer end, you can patch the current record - and update the current record with the result of Patch.

Set(
    currentRecord,
    Patch(
        datasourcename,
        currentRecord,
        EditForm1.Updates,
        EditForm2.Updates))

 

ck25415
Level 8

Re: Autosave with timer control with loop enabled

Hello @CarlosFigueira,

 

Thank you, that worked but whenever the timer ends after submitting the data to the sharepoint list its also clearing the existing text in the powerapps. Is there way to continue from the last word entered in the text field.

PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Autosave with timer control with loop enabled

Not if you're using forms; when you use a form, and a data source is updated (i.e., in a Patch operation), then the form will take the result of the operation and make any updates that the server has - and will reset its fields to take those values.

 

You may be able to go avoid using forms (for an example, see this blog post by @Meneghino), but you will need to handle the updates yourself. You can also have several "checkpoints" where the user will initiate a save (Patch) operation, instead on relying on a timer to do that on the user's behalf.

ck25415
Level 8

Re: Autosave with timer control with loop enabled

Hello Carlos,

By setting the item property of the form to empty(i.e nothing in the field) I was able to see the previous saved text and was able to make further changes to text and update the item in SharePoint. Do you think that the method suggested by you in the blog is better way to deal this problem, please suggest.
PowerApps Staff CarlosFigueira
PowerApps Staff

Re: Autosave with timer control with loop enabled

I haven't tried setting the Item in the form to empty, so if it works for you, then great. The blog post gives you more control over the layout / data, with the drawback that you need to handle the changes yourself.

 

Remember, however, that many times you do want to get the updated item from the server after a Patch operation (when someone else edited the item, if there are any server-generated columns, etc), so ignoring the result from the server (which you will do if you set the item to blank) may lead to hard-to-find problems.

Helpful resources

Announcements
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

Users Online
Currently online: 220 members 5,326 guests
Please welcome our newest community members: