Problem with multiple 'for each' statements in workflow
New to ZC and almost a novice at coding. I'm mostly getting along fine learning Deluge through the documentation and googling, but I'm completely stuck on this one. At line 22 I get the error 'Variable Actual_Work_Time does not exist in Activity_log'. I've tried every way I can think of to specify that 'Actual_Work_Time' is in the form Projects (not the subform Activity_log) but it won't accept any.
Forms/fields (only for as far as the problematic line):
- Projects (fields Total_Project_Time_Actual)
- subform Tasks (fields Live_for_Logging, Actual_Work_Time)
- subform Activity_log (fields Start_Logging, End_Logging, Total_Time)
The problematic line is supposed to sum the Actual_Work_Time fields in the Tasks subform and input the result in the Total_Project_Time_Actual field of the Projects form.
The code works except for line 22 (it runs fine if I comment the line out).
It runs on successful form submission of the Activity_Log form (the variant capitalisation is correct - it's Activity_Log as a form but Activity_log when it's a subform of Tasks).
Any help greatly appreciated!
- task = Tasks[ID = input.Task_ID];
- project = Projects[ID = task.Project];
- if(Start_Logging = "Yes")
- {
- input.Start_Logging = "No";
- openURL("#Script.page.close","same window");
- openURL("#Page:Timekeeping","same window");
- }
- if(End_Logging = "Yes")
- {
- task.Live_for_Logging="No";
- totaltask = 0;
- for each r in Activity_log[Task_ID == task.ID]
- {
- totaltask = totaltask + r.Total_Time;
- }
- task.Actual_Work_Time=totaltask;
- totalproject = 0;
- for each r in Tasks[Project == project.ID]
- {
- totalproject = totalproject + r.Actual_Work_Time;
- }
- project.Total_Project_Time_Actual=totalproject;
- task.Actual_Fee_Per_Hour=task.Actual_Fee / task.Actual_Work_Time;
- taskvalueactual = task.Actual_Fee;
- tasktimeactual = task.Actual_Work_Time;
- for each r in Activity_log
- {
- logvalueactual = taskvalueactual / tasktimeactual * input.Total_Time;
- }
- input.Log_Value_Actual_Fee = logvalueactual;
- taskvalueest = task.Estimated_Fee;
- tasktimeest = task.Estimated_Work_Time;
- if(task.Estimated_Fee = 0 || task.Estimated_Fee = null || task.Estimated_Work_Time = 0 || task.Estimated_Work_Time = null)
- {
- //do nothing
- }
- else
- {
- for each r in Activity_log
- {
- logvalueest = taskvalueest / tasktimeest * input.Total_Time;
- }
- }
- input.Log_Value_Estimated_Fee = logvalueest;
- input.End_Logging = "No";
- openURL("#Script.page.close","same window");
- openURL("#Page:Timekeeping","same window");
- }