How can I prepopulate one form with data that has been previously entered in another form, in same application?

How can I prepopulate one form with data that has been previously entered in another form, in same application?

To fetch data from a form and use it in another form, a relationship has to be established between the two forms, using Lookup fields. To create relationships between forms using Lookup fields, refer the topic Creating relationship.  Let us illustrate this with the help of an example. The sample application has two forms:

Customer form holds the customer details as shown in the Customer view given below:


New Request form is used to enter a new service request from a customer. This will have the Customer_Number as a lookup field from Customer form and other fields to display the customer details and request details., as shown in the New Request form given below. When a Customer Number is selected from the list, the customer details like, Name, Address etc will be displayed from the Customers Form.



Deluge Script : To achieve the above requirement, we have to add on user input script to the Customer_No field in the New Request form, as shown below:

        // check if the customer already exists

if (count(
Customers [Customer_Number == input.Customer_No]) > 0)  
 
// if exists, fetch records that satisfy the given criteria, and store it in a collection variable
temp = Customers [Customer_Number == input.Customer_No];
       // update the current form fields with the fetched data 
        input.Customer_Name = temp.Name;
        input.Plot_Number = temp.Plot_no;
        input.Address = temp.Address;
        input.E-mail = temp.Email;
        input.Phone_number = temp.Phone;
        input.Post_Code = temp.postcode;


Code Explanation:

temp = Customers [Customer_Number == input.Customer_No]; Fetch records from Customers form with the given criteria and store it in collection variable named "temp"

input.Customer_Name = temp.Name; Update the Customer_Name in the current form from the variable "temp". Here,input.Customer_Name refers to the customer name field in the current form and temp.Name is the customer name field fetched from the "Customers" form.