Welcome to Portal

?Unknown\pull-down

Welcome to Zoho Cares

Bienvenido a Soporte de Zoho

Search our knowledge base, ask the community or submit a request.

Auto populate a field based on the selection from a lookup dropdown

Requirement  

When a value is chosen from a lookup dropdown, related values are populated in the other fields of the same form.

Use Case  

An order management app contains a form to store order details. When the admin chooses the customer name from the dropdown, the customer details will be auto-populated. Similarly, when the admin chooses a product that is a lookup field in a subform, other related fields like Unit of measurement and Unit price will be auto-populated.

Steps to follow  

1. Create three forms with the following details:
Form
Form Link Name
Field Type
Field Name
Field Link Name
Customers
Customers
Name
Customer Name
Customer_Name
Number
Customer ID
C_ID
Phone Number
Phone_number
P_No
Products
Products
Single Line
Product
Product
Currency
Price
Price
Single Line
Unit of measure
Unit_of_measure
Orders
Orders
Lookup
(Customers)
Customer Name
Customer_Name
Single Line
Customer ID
Customer_ID
Phone Number
Phone number
Phone_number
Subform
  • Lookup
    (Products)
  • Number
  • Currency
  • Number
  • Currency
Products
  • Products
  • Unit of measure
  • Unit Price
  • Quantity
  • Total
Products
  • Products
  • Unit of measure
  • Unit_Price
  • Quantity
  • Total
 
2. Create a workflow with the following details:


This workflow is to disable the fields of the Orders form that will be auto populated, hence we are selecting the Form Event as "Load of the form".
 
3. Click Add New Action and save the following deluge snippet in the deluge editor:
  1. disable Customer_ID;
  2. disable Phone_number; 

4. Create a workflow with the following details.

The workflow is to be triggered when a user inputs a value to the Customer Name field of the Orders form is successfully submitted, so we are selecting the Form Event as "User input of a field".

5. Click Add New Action.

6. Save the following Deluge snippet in the Deluge editor:
  1. if(Customer_Name != null)
  2. {
  3. // Fetch the record corresponding to the selected customer name from Customers form
  4.  related_record = Customers[ID == input.Customer_Name];

  5. // Update fields with the related values fetched from Customers form
  6.  input.Customer_ID = related_record.C_ID;
  7.  input.Phone_number = related_record.P_No;
  8. }

input.<lookup field> returns the ID of the parent form record that contains the selected value. So, the above snippet uses ID == input.Customer_Name as criteria to fetch the corresponding record from the Customers form.
 
7. Next, let's try populating subform fields based on a subform field. Create workflow with the following details.

The workflow is to be triggered when a user inputs a value for the Products subform field of the Orders form, so we are selecting the Form Event as "User input of a field".
 
8. Click Add New Action and s ave the following Deluge snippet in the Deluge editor:
  1. if(row.Products != null)
  2. {
  3. // Fetch the record corresponding to the selected product from Products form
  4. related_record = Products[ID = row.Products];

  5. // Update fields with the related values fetched from Customers form
  6.  row.Unit_of_measure=related_record.Unit_of_measure;
  7.  row.Unit_Price=related_record.Price;
  8. }

See how it works     


Points to note  

  • input.<LookupField> returns ID of the record in parent form. Similarly, to insert a value into a lookup field, set ID of the record in the parent form as value to the field.

Helpful?30
Updated: 2 years ago
Share :