Its important to highlight that this post assumes you are already familiar with proper subform creation in Zoho Creator. If you are not please check out our Master Zoho Creator Subforms course in the url below before implementing this custom function.
That being said let´s jump on to the process in question. We are using a Gym App for testing and the goal is to add Classes to a New Member dinamically so user does not have to add classes everytime.
First, you need to call ( get ) the Member record you are going to be working with. Second, you want to create a Form with the records you want to add. In this case our Main Courses is a predetermined number of classes a member can take. You can update this records , delete them or add more as needed. The custom function will iterate through all these records in order to add them into the corresponding subform.
And last but not least you push ( Add ) the records in the Main Classes form into the subform Classes as shown in the custom function below
void Create.subformrows(int mid)
//First Step: To call ( get ) the record in question.
member = Members[ID == input.mid];
//Second Step: Iterate through the records you want to add to the subform
for each rec in Main_Clasess[ID != null]
//Step Three: Insert data into the subform
cla = insert into Clases