Custom Functions - Subform - Create Record

Custom Functions - Subform - Create Record

Hi, 

I am using the code below to create an invoice within the deal record, this works, however I would like for it to take the data from a subform, and this is something I am struggling with, can anyone help?

My subform is within the deals module and uses the following fields these are the API names... Product_Name_Lookup1, Product_quantity1, Product_list_price1, Product_total1, Product_net_total1, Product_description1 and I would like it to take each line from the subform, is this possible?

Thanks
Ant 

potDetails = zoho.crm.getRecordById("Deals",dealId.toLong());
RelatedProducts = zoho.crm.getRelatedRecords("Products","Deals",dealId.toLong());
pdlist = List();
for each  eachProd in RelatedProducts
{
proname = ifnull(eachProd.get("Product_Name"),"");
proid = ifnull(eachProd.get("id"),"");
mp = Map();
mp.put("product",{"name":proname,"id":proid});
mp.put("quantity",1);
mp.put("list_price",ifnull(eachProd.get("Unit_Price"),"0.0").toDecimal());
mp.put("total",ifnull(eachProd.get("Unit_Price"),"0.0").toDecimal());
mp.put("net_total",ifnull(eachProd.get("Unit_Price"),"0.0").toDecimal());
mp.put("product_description",ifnull(eachProd.get("Description"),""));
pdlist.add(mp);
}
paramap = Map();
paramap.put("Product_Details",pdlist);
paramap.put("Subject",ifnull(potDetails.get("Deal_Name"),""));
paramap.put("Owner",ifnull(potDetails.get("Owner"),"").get("id"));
paramap.put("Contact_Name",ifnull(potDetails.get("Contact_Name"),"").get("id"));
paramap.put("Account_Name",ifnull(potDetails.get("Account_Name"),"").get("id"));
paramap.put("Valid_Till",addDay(today,30));
paramap.put("Status","Created");
paramap.put("Deal_Name__s",ifnull(potDetails.get("id"),""));
paramap.put("Description",ifnull(potDetails.get("Description"),""));
createResp = zoho.crm.createRecord("Invoices",paramap);
info paramap;
info createResp;
newid = createResp.get("id");