Choose where you’d like to start

Insert rows in Subform

Note: This task is applicable only to Zoho Creator.

Overview

This task is used to dynamically insert rows into a subform. 

Note: This task not supported for custom sorting enabled subforms.

Syntax

// declaring the row
<row1> = <mainForm_linkName>.<subForm_linkName>();

// assigning values for various subform fields in the row
<row1>.<field_linkName> = <value>;
<row1>.<field_linkName> = <value>;

// declaring another row (declare as many rows as required)
<row2> = <mainForm_linkName>.<subForm_linkName>();

// assigning values for various subform fields in the row
<row2>.<field_linkName> = <value>;
<row2>.<field_linkName> = <value>;

// declare a variable to hold the collection of rows
<variable> = Collection();

<variable>.insert( <row1>, <row2> );

// insert the rows into the subform through the variable
input.<subForm_linkName>.insert( 
<variable> );
ParameterDescription
<rowN>Variable to represent an individual row
<mainForm_linkName>Link name of the parent form in which the subform exists
<subForm_linkName>Link name of the subform in which the rows will be added
<field_linkName>Link name of the subform field
<value>Value that will be assigned to the subform field
<variable>Variable to hold a collection of rows

Note:

  • This task can be used to assign values to subform fields while adding or updating records using Deluge scripts. For example, the following snippet assigns values to subform fields while using the add record task:
    <row1> = <mainForm_linkName>.<subForm_linkName>();
    <row1>.<field_linkName> = <value>;

    <rows> = collection();
    <rows>.insert(<row1>);

    <variable> = insert into <mainForm_linkName>
    [
        <subForm_linkName> = <rows>
    ];
  • If the script execution encounters an issue while the process of inserting rows is underway, the behavior of this task will be as follows:
    • Script written in On Load and On User Input: Rows that have been inserted will remain so, and the remaining rows will not be inserted
    • Script written in On Validate and On Success: None of the rows will be inserted.

This task can be used in the following events

When a record is Created
On LoadYes
On ValidateYes
On SuccessYes
On User inputYes
Subform on add rowYes
Subform on delete rowYes
When a record is Created or Edited
On LoadYes
On ValidateYes
On SuccessYes
On User inputYes
Subform on add rowYes
Subform on delete rowYes
When a record is Edited
On LoadYes
On ValidateYes
On SuccessYes
On User inputYes
On UpdateYes
Subform on add rowYes
Subform on delete rowYes
When a record is Deleted
On ValidateNo
On SuccessNo
Other workflow events
On a scheduled dateYes
During approval processYes
During payment processYes
In a Custom FunctionYes
In an Action item in reportYes

Example 1: Autopopulate subform fields on load of the form

Let's say we have a Products form that has a subform field Items. The subform has fields "Item Name", "Quantity", and "Price". We need to populate the subform fields "Item Name" and "Quantity" with values "Laptop" and 1 respectively. The following snippet (written in the On Load section) can be used in this scenario:

row1 = Products.Items(); 
row1.Item_Name = "Laptop"; 
row1.Quantity = 1; 
input.Items.insert(row1);

Example 2: Insert records fetched from one subform to another

The following script fetches the subform record in the form - form1 and inserts the record in the subform of the form - form2:

// Create a variable to store fetched records from the form1 
fetch_records = form1[ID != 0]; 
for each entry in fetch_records 
 { 
 fetch_subform1 = entry.subform1; 
 //Create a collection to store the data of each record in subform1 
 rows_collection = collection(); 
 for each data in fetch_subform1 
      { 
        row1 = form2.subform2(); 
        row1.Product_Name = data.Product; 
        row1.Qty = data.Quantity; 
        rows_collection.insert(row1); 
     }  
//Use Add Records task to insert the fetched subform1 values stored in the collection - row_collection in the subform2 in form2 
 response = insert into form2 
 [ 
    subform2 = rows_collection 
 ]; 
 }

where:

form1
is the TEXT that represents the link name of the parent form where the subform records needs to be fetched.
subform1
is the TEXT that represents the link name of the subform where the records needs to be fetched.
form2
is the TEXT that represents the link name of the parent form where the subform records needs to be inserted.
subform2
is the TEXT link name of the subform that needs to be inserted with fetched records.
rows_collection
is the Collection that stores the fetched records from subform1.

Get Started Now

Execute