Insert rows in Subform
Table of Contents
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> );
<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> );
Parameter | Description |
---|---|
<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 Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Created or Edited | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Edited | ||
On Load | Yes | |
On Validate | Yes | |
On Success | Yes | |
On User input | Yes | |
On Update | Yes | |
Subform on add row | Yes | |
Subform on delete row | Yes | |
When a record is Deleted | ||
On Validate | No | |
On Success | No | |
Other workflow events | ||
On a scheduled date | Yes | |
During approval process | Yes | |
During payment process | Yes | |
In a Custom Function | Yes | |
In an Action item in report | Yes |
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.