cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RoB-E
Helper I
Helper I

How to code last submit in a dropdown?

I'm new to power apps and just trying to code a drop down to return last submittedvalue on newform  not sure how to and help would be much appreciated. The app I'm working on will create 20 to 30 records a day with the same block number. So I need the dropdown value to defualt to last selected value  when submitted on new form 

1 ACCEPTED SOLUTION

Accepted Solutions

@RoB-E 

 

Yes try like this.

 

Presuming a Form called Form1 and a button called Button1 and a data source called List01 (such as a SharePoint List, for example):

 

Form1 DefaultMode

 

FormMode.New

 

 

Form1 Item

 

If(!IsBlank(First(Coll_Last_Submit)),First(Coll_Last_Submit),Defaults(List01))
//Instead of List01 above, use the name of your SharePoint List or data source.

 

 

Form1 OnSuccess

 

Clear(Coll_Last_Submit);Collect(Coll_Last_Submit,Form1.LastSubmit);Patch(Coll_Last_Submit,First(Coll_Last_Submit),{ID:Blank()})

 

or

 

ClearCollect(Coll_Last_Submit,Form1.LastSubmit);Patch(Coll_Last_Submit,First(Coll_Last_Submit),{ID:Blank()})

 

 

Button1 OnSelect

 

SubmitForm(Form1);

 

 

This should work, and the New form after submit, will have all the previous values based on the last submitted record, but still be a new form mode. After the next submit, it should create a brand new record.

 

If the above does not work, properly i.e. for example, if for some reason it just keeps editing the same last submitted record over and over again, it could be because the part where Patch of Blank() value for ID, might not work and not actually remove the ID (thus editing the same last submitted record over and over again), unless a specific setting is turned on in the app called Formula-level error management . So if it does not work, try these steps as well below first:

 

1. Click on Settings

poweractivate_0-1663814617897.png

 

2. In the modal, click on Upcoming Features -> Preview ->  Formula-level error management - set this toggle, to "On"

poweractivate_1-1663814663230.png

3. Close this modal.

4. Save and Publish the app.

5. Close the whole Power Apps editor.

6. Go to make.powerapps.com, select the right environment, find your app for editing, and open it up for editing. If you just made this app recently and it's missing from the list for some reason, just try making a new blank app, and the one that is missing might now appear in the list.

7. Try the app now and see if it works.

 

This setting has been around for quite a long time, it is often turned on for this kind of scenario, the fact that it is labeled "Preview" may not be so much of a concern, I doubt the feature is going away in the future. While that is technically subject to change, I am not able to think of a better way to accomplish your scenario. First try and see if it works with the Formula-level error management setting off (the default). If it does, then great. If it does not (and I suspect that it might not), this setting Formula-level error management  may have to be set to On for this solution to work properly. Please note that after turning it on, it may be necessary to close and reopen the app for editing as stated in the above steps, if it is still not making a new record on each submit, so that the setting could fully take effect.

 

See if it helps @RoB-E 

View solution in original post

16 REPLIES 16

@RoB-E 

 

Could you check if LastSubmit - docs.microsoft.com could achieve your goals?

 

LastSubmit – The last successfully submitted record, including any server generated fields.

  • This property applies only to the Edit form control.
  • If the data source automatically generates or calculates any fields, such as an ID field with a unique number, the LastSubmit property will have this new value after SubmitForm successfully runs.
  • The value of this property is available in the OnSuccess formula.


 

SudeepGhatakNZ
Helper V
Helper V

In your Save or Submit button, add this code.

ClearCollect(ColLastItem, Submitform(FormName));

 

Like @poweractivate mentioned, you can also try Formname.LastSubmit

Ok so my save button  onselect has this code: SubmitForm(EditForm1)ResetForm(EditForm1)NewForm(EditForm1) do I add it to the end or beginning of this ?

SudeepGhatakNZ
Helper V
Helper V

ClearCollect(ColLastItem, Submitform(EditForm1));ResetForm(EditForm1);NewForm(EditForm1)

So if my last submission dropdown was say 205 it would still be 205 on the newform after submit? 

SudeepGhatakNZ
Helper V
Helper V

Your Newform won't have an ID until the form is submitted back again.

SubmitForm will only return the ID of the record that it just submitted

Ok so I'm a bit confused? I need the newform to show the submitted forms value in the drop down. So if I submit a value of 203 I need the newform to show that last submitted value 

I tried the formula  and it had no errors but it did not return the dropdown to my last selected value. Is there away to make that happen?

SudeepGhatakNZ
Helper V
Helper V

What value did it return in ColLastItem? Are you able to check that by adding a label and setting its text property to ColLastItem? Just so that we are clear, ColLastItem will return you ID of the new record created in SharePoint List.

In case I am not following you, a screenshot might help

Helpful resources

Announcements
Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Power Platform Conference Sold Out

Power Platform Conference-Sold Out!

We are so excited to announce that the Power Platform Conference is sold out!

Super User 2 - 2022 Congratulations

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

<
Users online (2,721)