Auto-populate subform data from a form based on lookup selection | Zoho Creator Help

Auto-populate subform data from a form based on lookup selection

Requirements

Streamline the process of retrieving and displaying relevant data by auto-populating a subform based on the value selected in a lookup field.

Use Case

Consider an IT asset management application used by organizations to conduct asset audits. The process is streamlined through a dynamic data-loading feature in the asset audit form. When an auditor selects an employee’s name from the lookup field, the subform automatically populates with all relevant asset details associated with that employee, retrieved from the asset details form. This feature provides auditors with immediate access to employee-specific asset details, enabling real-time asset tracking and verification.

Steps to follow

  1. Create forms with the following fields for storing employee and asset details, which can auto-populate in a subform.

    Form

    Form Link Name

    Field Type

    Field Name

    Field Link Name

    Employee Details

    Employee_Details

    Name

    Employee Name

    Employee_Name

    Email

    Email

    Email

    Phone

    Phone

    Phone

    Address

    Address

    Address

    Asset Details

    Asset_Details

    Look up
    (Employee Details)

    Employee Name

    Employee_Name

    Drop Down

    Asset Category

    • Laptop

    • Mobile

    • Hardware

    Asset_Category

    Single Line

    Model

    Model

    Single Line

    Serial Number

    Serial_Number

    Asset Audit

    Asset_Audit

    Lookup
    (Employee_Details)

    Employee Name

    Employee_Name

    Subform

    • Single Line

    • Single Line

    • Single Line

    • Drop Down

    Assets Owned

    • Asset Category

    • Model

    • Serial Number

    • Verification (Passed/failed)

    Assets_Owned

    • Asset_Category

    • Model

    • Serial_Number

    • Verification

  2. Create a workflow to execute on user input of the Employee Name lookup field in the Asset Audit form. This workflow will be configured to auto-populate the asset details of the employee in the subform.

  3. Click Add New Action and enter the following script in the Deluge editor.
    1. //Fetch all assets of the employee 
    2. fetch_records = Asset_Details[Employee_Name == input.Employee_Name];
    3. //Create a collection to store the fetched subform data.
    4. rows_collection = Collection();
    5. for each data in fetch_records
    6. {
    7. row = Asset_Audit.Assets_Owned();
    8. row.Asset_Category = data.Asset_Category;
    9. row.Model = data.Model;
    10. row.Serial_Number = data.Serial_Number;
    11. rows_collection.insert(row);
    12. }
    13. //Insert the collection to the subform
    14. input.Assets_Owned.insert(rows_collection);
  4. Create another workflow in the Asset Audit form by selecting the Record Event as Created or Edited and Form Event as Field rules. This workflow will prevent the user from adding and deleting the auto-populated subform rows.

  5. Click Add New Action > Show/Hide subform actions > Hide subform add entry and select the Asset Owned subform. In the same workflow, click Add New Action > Show/Hide subform actions > Hide subform delete entry and select the Asset Owned subform.

  6. You can also choose to disable the auto-populated subform fields by creating another workflow on load of the Asset Audit form by selecting the Record Event as Created or Edited, as shown.

  7. Click Add New Action > Deluge Script and add the following script in the Deluge editor.
    1. disable Asset_Owned.Asset_Category;
    2. disable Asset_Owned.Model;
    3. disable Asset_Owned.Serial_Number;

See How it Works


  1. Insert rows in Subform
  2. Understand on delete row action in subform
  3. Understand on add row action in subform