In some of the client projects you might run into a requirement where they wish to start a new request but instead of making the user fill in all the data from scratch, they wish to copy over the data from one of the previous request they had submitted. This is often the case when revisions are being made to original request like generating quotes with minor changes.
There are multiple ways of doing this.
Option 1: Using Data Population or Insert/Update Database shapes
Overall it is better to design app to go against master source which is a database or may be Salesforce, ShapePoint etc. directly to load data where approved data is eventually stored at rest. It can be done without writing any JavaScript with use of Pop-Up Select and a lookup. I have created a small sample for you for loading my expense report based on past data. All I have in JavaScript is just 5-6 lines of code and that too is for UI operations like reset selected data. This is just a sample as per my scenario. I used database shapes to insert approved record in tables at end of process but could have been SharePoint List or Salesforce object as well. I could have also used data services for OnPrem scenarios but using database shapes will work everywhere which anyways a realistic project would need a permanent data store instead of just keeping data in XML so there would always be a database or SharePoint List or a master data source of some sort.
Try running the attached app and you can see how it can be done without writing code. Feel free to replace any database tables or shapes as per your needs as this is a sample.
Download the scripts for creating the database tables used by the app
Download the Expense Report app sample
Reusable Data App – Expense_Report
Screen 1:
Provided an option in the right side of the form to select the data from the Previous “Requests”. If user clicks the link we are opening a popup window with the existing records. User can select the record and click on ‘OK’ button we are loading the data in the form.
Screen 2: Popup Window with existing records from past submissions
Screen 3: Existing Data Loaded.
I have attached the Application, DB Script and Insert Data Script. Since it brings down only logged in user’s row, you will need to replace EmployeeName in ExpenseMaster with your machine’s logged in username to bring any data else you will continue getting
Database Name: [ExpenseReport] – You need to create this and execute attached scripts and change access token at app level to point to this database. Right now it is pointing to my machine.
Option 2: Pass previous process instance ID to the start form using querystring parameter
If you know the process instance ID of the previous instance, you can just pass that in the querystring parameter and the form has inbuilt intelligence to load the previous data automatically on the new form. The parameter to be passed is PreviousPIID
The URL might look something like the one shown below
http://csc-lead:13491/ApplicationBuilder/eFormRender.html?Process=Customer%20Order%20Management&PreviousPIID=82BC0021CCD865921166C0F0B8E16F86
One thing to note in this approach is that it will only load data for controls which is available on the start form and ignore the values from previous instance for any controls which were not present on the current start form.