Create records in embedded subform

Create records in embedded subform

Hello,

I have a main form (Scheduler) and added a subform to it (Product_Subform).. I can create records to add an new appointment repeating every X weeks that matches an existing appointment... but I want to also duplicate the subform records in the new appointments that are being created.

Thanks,
Jason

  1. //get current appointment record
  2. myApptID = input.ID;
  3. //repeat appointments
  4. repeatInterval = input.Reoccurring_Appointment;
  5. if(len(repeatInterval) > 0)
  6. {
  7. //get substring
  8. repeatIntervalDuration = repeatInterval.subString(1,2).toLong() - 1;
  9. if(repeatIntervalDuration = 2)
  10. {
  11. repeatIntervalDuration = 11;
  12. }
  13. //loop
  14. //create number to loop thru
  15. loop_list = {"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
  16. for each index myIndex in loop_list
  17. {
  18. if(myIndex <= repeatIntervalDuration)
  19. {
  20. //calculate weeks
  21. daysToRepeat = (myIndex + 1) * 7;
  22. // insert into scheduler form  *This is working* creates new records
  23. recordID = insert into Scheduler
  24. [
  25. Client=input.Client
  26. Appointment_Type=input.Appointment_Type
  27. Practitioner=input.Practitioner
  28. Practitioner_User_Filter=input.Practitioner_User_Filter
  29. Ending_On=input.Ending_On.addDay(daysToRepeat)
  30. Beginning_On=input.Beginning_On.addDay(daysToRepeat)
  31. Added_User=zoho.loginuser
  32. Map_URL=input.Map_URL
  33. Map_URL_Client=input.Map_URL_Client
  34. Full_Name=input.Full_Name
  35. Visit_Notes=input.Visit_Notes
  36. Email=input.Email
  37. Client_Email=input.Client_Email
  38. Entry=input.Entry
  39. Total_Amount=input.Total_Amount
  40. ];
  41. // trying to add charges for each subform item - *This is NOT working - it creates records but they are not related to the appointment above - when I look at the appointment on those new records they don' t have any services listed like the original appointment has..*
  42. myRecord = Scheduler[ID == myApptID];
  43. for each  myField in myRecord.Services
  44. {
  45. insert into Product_SubForm
  46. [
  47. Added_User=zoho.loginuser
  48. SchedulerLink=recordID
  49. Product_Name=myField.Product_Name
  50. Product_Quantity=myField.Product_Quantity
  51. Product_Price=myField.Product_Price
  52. Product_Total=myField.Product_Total
  53. ]
  54. }
  55. }
  56. }
  57. }