1. Capture the Last Submitted Record
2. Modify the "New" Button
Ensure that when users click "New", the form is reset to default values and any duplication flags are cleared:
3. Add a "Duplicate" Button
Place the "Duplicate" Button on Screen1 or Screen2 Decide where you want the "Duplicate" button. If you place it on Screen1, set its OnSelect property as:
Set(isDuplicating, true);
EditForm(Form1);
Navigate(Screen2);
4. Set Up a Duplication Flag
Use isDuplicating to track whether the form should pre-populate with the last submitted data.
Set(isDuplicating, false);
5. Configure Form1 to Use the Last Record
Item Property of Form1
Set the Item property of Form1 to:
If(isDuplicating, LastRecord, Blank())
6. Modify the Submit Button to Create a New Record
OnSelect Property of the Submit Button - Since the form is in Edit mode but we want to create a new record, use the Patch function:
Patch(
DataSourceName,
Defaults(DataSourceName),
Form1.Updates
);
ResetForm(Form1);
Set(isDuplicating, false);
Navigate(Screen1);
7. Reset Duplication After Submission
The Set(isDuplicating, false); line ensures that after submitting the duplicated data, the form doesn't retain the duplication state.
8. Handle First-Time Users or No Previous Data
Check if LastRecord is Available - In the OnSelect property of the "Duplicate" button, ensure LastRecord is not empty:
If(
!IsBlank(LastRecord),
Set(isDuplicating, true);
EditForm(Form1);
Navigate(Screen2),
Notify("No previous data to duplicate.", NotificationType.Warning)
)
By capturing the last submitted record and cleverly using form modes and variables, you can enhance your app to allow users to duplicate their previous submissions easily. This improves user experience by saving time and reducing data entry errors.
Let me know if you have any questions or need further assistance implementing this solution!