Schedule for each record in Form and Subform
Hello!
We are developing an app (very similar to the "Order Management 2.0" app in Marketplace).
I'm trying to create (using Schedules) a new CRM Invoice for each record (client), but every Invoice must contain all Items added with the subform.
I'm using the next code (in Schedules), but the Items are not added correctly:
- for each record in Order_Form
{
Grand_Total=0.0;
Products=List:Map();
for each Item_Subform in Order_Form
{
Total= Item_Subform.Price * Item_Subform.Quantity;
Grand_Total= (Grand_Total + Total);
Products.add({ "Product Id" :Item_Subform.ID_Product, "Product" : Item_Subform.ProductName, "Quantity" : Item_Subform.Quantity, "Unit Price" : Item_Subform.Price, "List Price" : Item_Subform.Price, "Total" : Total, "Net Total" : Total, ("Total After Discount") : Total });
}
New_Invoice = zoho.crm.create("Invoices",{ "Subject" : "Invoice " + record.Client_Name, ("Account Name") :record.Client_Name, "Grand Total" : Grand_Total, "Products" : Products },2);
}
The exact same Items are added in every Invoice in CRM (the first Item in every order). If I have 5 orders, the first Item in every Order is added to each Invoice in CRM, with the same Invoice Total.
Thank you for all your help.