Auto populate a form with data fetched from another form
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 like Customer Number, name, address, post code, phone number and email address
- 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. 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 Number field in the New Request form, as shown below:
temp = Customer [ID == input.Customer_Number];
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;
Check if the customer already exists. If exists, fetch records that satisfy the given criteria, and store it in a collection variable. Update the current form fields with the fetched data
temp = Customer [ID == input.Customer_Number]; 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.