Add Entry and Subform Record from Deluge Scripts

Add Entry and Subform Record from Deluge Scripts

Hi all,

 I would like to know how do I add a new entry and also subform records from a deluge scripts.

 I can use the insert into to add a new entry to a form, but how do i insert a collection into the subform of the entry?

I am using a deluge script upon successful submission, the script will insert a record in another form, but I have difficulty understand the steps to insert the subform records.

I'm using the following method:

for each record in Form1.Subform1
{
row = Form2.Subform2();
row.Field1= record.Value1;
row.Field2= record.Value2;
rowcollection = Collection();
rowcollection.isert(row);
Subform2.insert(rowcollection);
}

But I not sure how do i map the subform record to the main record... Any help will be highly appreciate.