How to copy a subform data to another subform using a report action | Zoho Creator Help

How to copy subform data to another subform using a report action

The values in a subform of a record can be copied to another form's subform using Deluge within the report actions. This allows seamless transfer of subform data between forms, ensuring consistency.

For example, consider a Zoho Creator resource management application where teams raise product requests with the list of products in a subform. The manager can verify these requests from the form's report. After verification, the requests are directly converted into purchase orders by duplicating the requested materials from the subform into the purchase order form's subform. This is triggered when the report action is clicked on the preferred record.

Prerequisites

In order to transfer data from one subform to another in your application, both subforms must have the same type of fields across two different forms. Here for demonstration purposes, we'll be creating the forms Form A with the subform field Subform A and Form B with the subform field Subform B by replicating the same fields in Subform A to transfer the subform data from Form A to Form B
Additionally, a number field ID_Number is added in Form B to store the ID of the record from which the action item is triggered in Form A's report. The subform data will be fetched from Form A by matching the record's ID stored in the ID_Number field, and then populated into Subform B in Form B.
Form A:


Form B:

Steps to follow

  1. Navigate to the report of Form A in the edit mode of the application. Configure an action item with the name 'Copy Subform' for a single record by creating a workflow and adding the following Deluge script to the workflow. When this action item is triggered, it will open Form B and populate the ID of the selected record to the ID Number field in Form B.
    1. //Configure an openURL task to open the 'Form B' and populate the ID of the selected  record in the ID Number field of the 'Form B'.
    2. openUrl("#Form:Form_B?ID_Number="+input.ID, "same window");
  2. Add the action item to the quick view layout of Form A's report to access it as a button from the quick view of Form A's report.

  3. Create a new workflow to execute on load of Form B with the record event as Created. This workflow will fetch and populate the subform data from the From A.

  4. Click Add New Action > Deluge Script and add the following script to the Deluge editor.
    1. if(ID_Number != null)
    2. {
    3. //Fetch subform data of the selected record in 'Form A' by matching the autopopulated ID in the ID Number field.
    4. fetch_records = Form_A[ID == input.ID_Number].Subform_A;
    5. //Create a collection to hold subform rows.
    6. rows_collection = Collection();
    7. //Iterate through the each subform row in the 'Form A' to fetch and assign values from Subform A in 'Form A' to the Subform B in 'Form B'.
    8. for each data in fetch_records
    9. {
    10. subform_row = Form_B.Subform_B();
    11. subform_row.Single_Line_B = data.Single_Line_A;
    12. subform_row.Number_B = data.Number_A;
    13. rows_collection.insert(subform_row);
    14. }
    15. //Insert the subform rows stored in the collection to the 'Subform B'.
    16. input.Subform_B.insert(rows_collection);
    17. }
You can also choose to hide the ID Number field in Form B, as it is used internally for storing the ID to fetch the relevant record in Form A.

See how it works


  1. Insert rows in Subform
  2. Create Action Item
  3. openUrl