0
votes

Can anyone please guide me how to avoid the error 'The formula has exceeded the maximum allowable memory usage.' in my application, in which I wrote several complex logics using @Formulas.

In my application, several different activities are being performed as the user clicks on a button (perform several calculations, validation checks, updating several documents related to current document etc.). The code to perform these activities is about 600 lines long (written in Formula language), and several loops, and if-else's are being used here.

In few cases, where the no. of related documents (which gets updated when user clicks on the button) is high (more than 100), the system raises this error after executing few lines of code.

I removed some code which is of no use. Now the system is processing few more lines of code, and the error is coming on some different line of code.

Please suggest me how to avoid this problem as this is very critical system and users are not able to make any update because of this issue.

Following is complete code:

REM {Activities after saving document: Calculate the sum of completed HMRs and save in master document};
REM {Update each component entry of this machine
if component has not completed target hours, add current day's sum to it. };
REM {Calculate HMRs before and after current entry, send mail notification after each 500 hours, starting with 480 1st mail will be triggered on 480, 2nd on 980 and so on };
@If(@Command([FileSave]);
@Do(
varServer := @If(@ServerName = @UserName;"";@Name([CN];@ServerName));
lkpResult := @DbLookup("":"NOCACHE";varServer:@DbName[2];"vw_Daily_Logs";Machine_Line + "~" + Machine_ID;"Day_Run_Mileage");
shift_A_Run := @If(@Trim(@Text(Stop_HMR_A)) = "";0;Stop_HMR_A < Start_HMR_A;0;@Round(Stop_HMR_A - Start_HMR_A;0.1));
shift_B_Run := @If(@Trim(@Text(Stop_HMR_B)) = "";0;Stop_HMR_B < Start_HMR_B;0;@Round(Stop_HMR_B - Start_HMR_B;0.1));
shift_C_Run := @If(@Trim(@Text(Stop_HMR_C)) = "";0;Stop_HMR_C < Start_HMR_C;0;@Round(Stop_HMR_C - Start_HMR_C;0.1));
shift_A_Diesel := @If(Diesel_A = "";0;Diesel_A);
shift_B_Diesel := @If(Diesel_B = "";0;Diesel_B);
shift_C_Diesel := @If(Diesel_C = "";0;Diesel_C);
shift_A_Remarks := @If(Test_conducted_A = "Build/Part Fitment";"[PART FITMENT]:  "+ Test_Remarks_A;Test_conducted_A = "Breakdown/Hold";"[Breakdown/Hold]:  "+ Test_Remarks_A;Test_Remarks_A);
shift_B_Remarks := @If(Test_conducted_B = "Build/Part Fitment";"[PART FITMENT]:  "+ Test_Remarks_B;Test_conducted_B = "Breakdown/Hold";"[Breakdown/Hold]:  "+ Test_Remarks_B;Test_Remarks_B);
shift_C_Remarks := @If(Test_conducted_C = "Build/Part Fitment";"[PART FITMENT]:  "+ Test_Remarks_C;Test_conducted_C = "Breakdown/Hold";"[Breakdown/Hold]:  "+ Test_Remarks_C;Test_Remarks_C);
strRemarks := @If(@Trim(@Implode(Remarks_A)) = "";"";@Trim(@Implode(Remarks_A)));
strRemarks := strRemarks + @If(@Trim(@Implode(Remarks_B)) = "";"";@NewLine + @Trim(@Implode(Remarks_B)));
strRemarks := strRemarks + @If(@Trim(@Implode(Remarks_C)) = "";"";@NewLine + @Trim(@Implode(Remarks_C)));
strRemarks := @If(strRemarks = "";"-";strRemarks);
strRemarks := @ReplaceSubstring(strRemarks;",";".");
shift_A_Operator := @If(@Trim(Operator_A) = "";"-";Operator_A);
shift_B_Operator := @If(@Trim(Operator_B) = "";"-";Operator_B);
shift_C_Operator := @If(@Trim(Operator_C) = "";"-";Operator_C);
shift_A_Test := @If(@Trim(Test_conducted_A) = "";"-";Test_conducted_A);
shift_B_Test := @If(@Trim(Test_conducted_B) = "";"-";Test_conducted_B);
shift_C_Test := @If(@Trim(Test_conducted_C) = "";"-";Test_conducted_C);
meter_Change_HMR_Reading := Meter_Changed_At_HMR;
@If(@GetDocField(ParentUNID;"DateList")[1] = "-";
@Do(
@SetDocField(ParentUNID;"Total_Vehicle_Hours";Cumulative_Vehicle_Hours);
 varSerialNoList := "1";
Milage_Plan_Tmp := Milage_Plan;
varPlannedHrsList := @Text(Cumulative_Vehicle_Reading_Plan + Milage_Plan_Tmp);
plannedHRSCumulative := Cumulative_Vehicle_Reading_Plan + Milage_Plan_Tmp;
tmpTargetHMR := Target_HMR;
varActualHrsList := @Text(HMR_Start_Reading + shift_A_Run + shift_B_Run + shift_C_Run);
varHMR_A := @Text(shift_A_Run);
varHMR_B := @Text(shift_B_Run);
varHMR_C := @Text(shift_C_Run);
varHMR_Total := @Text(shift_A_Run + shift_B_Run + shift_C_Run);
varDiesel_A := @Text(shift_A_Diesel);
varDiesel_B := @Text(shift_B_Diesel);
varDiesel_C := @Text(shift_C_Diesel);
varDiesel_Total := @Text(shift_A_Diesel + shift_B_Diesel + shift_C_Diesel);
varRemarksList := @If(strRemarks = "";"-";strRemarks);
varRemarksList_A := @If(shift_A_Remarks = "";"-";shift_A_Remarks);
varRemarksList_B := @If(shift_B_Remarks = "";"-";shift_B_Remarks);
varRemarksList_C := @If(shift_C_Remarks = "";"-";shift_C_Remarks);
varOperatorList_A := @If(shift_A_Operator = "";"-";shift_A_Operator);
varOperatorList_B := @If(shift_B_Operator = "";"-";shift_B_Operator);
varOperatorList_C := @If(shift_C_Operator = "";"-";shift_C_Operator);
varTestList_A := @If(shift_A_Test = "";"-";shift_A_Test);
varTestList_B := @If(shift_B_Test = "";"-";shift_B_Test);
varTestList_C := @If(shift_C_Test = "";"-";shift_C_Test);
daysToRun := @GetDocField(ParentUNID;"DaysToRun");
targetHrs := @GetDocField(ParentUNID;"Target_HMR");
tmpDate := @Date(Log_Date);
datesList := @Text(tmpDate);
@For(tmpKtr := 2; tmpKtr <= daysToRun;tmpKtr := tmpKtr + 1;@Do(
tmpDate := @If(@Weekday(@Adjust(tmpDate;0;0;1;0;0;0)) =    1; @Adjust(tmpDate;0;0;2;0;0;0);@Adjust(tmpDate;0;0;1;0;0;0));
datesList := datesList : @Text(tmpDate);
varSerialNoList := varSerialNoList : @Text(tmpKtr);
plannedHRSCumulative := @If(plannedHRSCumulative + Milage_Plan_Tmp > Scheduled_Closing_HMR;Scheduled_Closing_HMR;plannedHRSCumulative + Milage_Plan_Tmp);
varPlannedHrsList := varPlannedHrsList : @Text(plannedHRSCumulative);
varActualHrsList := varActualHrsList  : "-";
varHMR_A := varHMR_A : "-";
varHMR_B := varHMR_B : "-";
varHMR_C := varHMR_C : "-";
varHMR_Total := varHMR_Total : "-";
varDiesel_A := varDiesel_A : "-";
varDiesel_B := varDiesel_B : "-";
varDiesel_C := varDiesel_C : "-";
varDiesel_Total := varDiesel_Total : "-";
varRemarksList := varRemarksList : "-";
varRemarksList_A := varRemarksList_A : "-";
varRemarksList_B := varRemarksList_B : "-";
varRemarksList_C := varRemarksList_C : "-";
varOperatorList_A := varOperatorList_A : "-";
varOperatorList_B := varOperatorList_B : "-";
varOperatorList_C := varOperatorList_C : "-";
varTestList_A := varTestList_A : "-";
varTestList_B := varTestList_B : "-";
varTestList_C := varTestList_C : "-"
));
@SetDocField(ParentUNID;"Total_Vehicle_Hours";Cumulative_Vehicle_Hours);
@SetDocField(ParentUNID;"SerialNoList";varSerialNoList);
@SetDocField(ParentUNID;"DateList";datesList);
@SetDocField(ParentUNID;"PlannedHrsList";varPlannedHrsList);
@SetDocField(ParentUNID;"ActualHrsList";varActualHrsList);
@SetDocField(ParentUNID;"Machine_Run_Time_A";varHMR_A);
@SetDocField(ParentUNID;"Machine_Run_Time_B";varHMR_B);
@SetDocField(ParentUNID;"Machine_Run_Time_C";varHMR_C);
@SetDocField(ParentUNID;"Machine_Run_Time_Total";varHMR_Total);
@SetDocField(ParentUNID;"DieselConsumedListShiftA";varDiesel_A);
@SetDocField(ParentUNID;"DieselConsumedListShiftB";varDiesel_B);
@SetDocField(ParentUNID;"DieselConsumedListShiftC";varDiesel_C);
@SetDocField(ParentUNID;"DieselConsumedListTotal";varDiesel_Total);
@SetDocField(ParentUNID;"RemarksList";varRemarksList);
@SetDocField(ParentUNID;"RemarksListA";varRemarksList_A);
@SetDocField(ParentUNID;"RemarksListB";varRemarksList_B);
@SetDocField(ParentUNID;"RemarksListC";varRemarksList_C);
@SetDocField(ParentUNID;"OperatorListA";varOperatorList_A);
@SetDocField(ParentUNID;"OperatorListB";varOperatorList_B);
@SetDocField(ParentUNID;"OperatorListC";varOperatorList_C);
@SetDocField(ParentUNID;"TestListA";varTestList_A);
@SetDocField(ParentUNID;"TestListB";varTestList_B);
@SetDocField(ParentUNID;"TestListC";varTestList_C);
@SetDocField(ParentUNID;"Meter_Changed_At_HMR";meter_Change_HMR_Reading)
);
@Do(
varSeqNoList := @GetDocField(ParentUNID;"SerialNoList")[1];
varDateList :=  @GetDocField(ParentUNID;"DateList")[1];
varPlannedHrsList := @GetDocField(ParentUNID;"PlannedHrsList")[1];
varActualHrsList := @GetDocField(ParentUNID;"ActualHrsList")[1];
varHMR_A := @GetDocField(ParentUNID;"Machine_Run_Time_A")[1];
varHMR_B := @GetDocField(ParentUNID;"Machine_Run_Time_B")[1];
varHMR_C := @GetDocField(ParentUNID;"Machine_Run_Time_C")[1];
varHMR_Total := @GetDocField(ParentUNID;"Machine_Run_Time_Total")[1];
varDiesel_A := @GetDocField(ParentUNID;"DieselConsumedListShiftA")[1];
varDiesel_B := @GetDocField(ParentUNID;"DieselConsumedListShiftB")[1];
varDiesel_C := @GetDocField(ParentUNID;"DieselConsumedListShiftC")[1];
varDiesel_Total := @GetDocField(ParentUNID;"DieselConsumedListTotal")[1];
varRemarksList := @GetDocField(ParentUNID;"RemarksList")[1];
varRemarksList_A := @GetDocField(ParentUNID;"RemarksListA")[1];
varRemarksList_B := @GetDocField(ParentUNID;"RemarksListB")[1];
varRemarksList_C := @GetDocField(ParentUNID;"RemarksListC")[1];
varOperatorList_A := @GetDocField(ParentUNID;"OperatorListA")[1];
varOperatorList_B := @GetDocField(ParentUNID;"OperatorListB")[1];
varOperatorList_C := @GetDocField(ParentUNID;"OperatorListC")[1];
varTestList_A := @GetDocField(ParentUNID;"TestListA")[1];
varTestList_B := @GetDocField(ParentUNID;"TestListB")[1];
varTestList_C := @GetDocField(ParentUNID;"TestListC")[1];
varDelayCount := 0;
@For(itemKtr := 2; itemKtr <= @Elements(@GetDocField(ParentUNID;"DateList")); itemKtr := itemKtr + 1;
varSeqNoList := varSeqNoList : @GetDocField(ParentUNID;"SerialNoList")[itemKtr];
varDateList := varDateList : @GetDocField(ParentUNID;"DateList")[itemKtr];
varPlannedHrsList := varPlannedHrsList : @GetDocField(ParentUNID;"PlannedHrsList")[itemKtr];
@If(@Text(@Date(Log_Date)) = @GetDocField(ParentUNID;"DateList")[itemKtr];
@Do(
varActualHrsList := varActualHrsList : @Text(HMR_Start_Reading + shift_A_Run + shift_B_Run + shift_C_Run);
varHMR_A := varHMR_A : @Text(shift_A_Run);
varHMR_B := varHMR_B : @Text(shift_B_Run);
varHMR_C := varHMR_C : @Text(shift_C_Run);
varHMR_Total := varHMR_Total : @Text(shift_A_Run + shift_B_Run + shift_C_Run);
varDiesel_A := varDiesel_A : @Text(shift_A_Diesel);
varDiesel_B := varDiesel_B : @Text(shift_B_Diesel);
varDiesel_C := varDiesel_C : @Text(shift_C_Diesel);
varDiesel_Total := varDiesel_Total : @Text(shift_A_Diesel + shift_B_Diesel + shift_C_Diesel);
varRemarksList := varRemarksList : @If(strRemarks = "";"-";strRemarks);
varRemarksList_A := varRemarksList_A : @If(shift_A_Remarks = "";"-";shift_A_Remarks);
varRemarksList_B := varRemarksList_B : @If(shift_B_Remarks = "";"-";shift_B_Remarks);
varRemarksList_C := varRemarksList_C : @If(shift_C_Remarks = "";"-";shift_C_Remarks);
varOperatorList_A := varOperatorList_A : @If(shift_A_Operator = "";"-";shift_A_Operator);
varOperatorList_B := varOperatorList_B : @If(shift_B_Operator = "";"-";shift_B_Operator);
varOperatorList_C := varOperatorList_C : @If(shift_C_Operator = "";"-";shift_C_Operator);
varTestList_A := varTestList_A : @If(shift_A_Test = "";"-";shift_A_Test);
varTestList_B := varTestList_B : @If(shift_B_Test = "";"-";shift_B_Test);
varTestList_C := varTestList_C : @If(shift_C_Test = "";"-";shift_C_Test)
);
@Date(Log_Date) > @TextToTime(@GetDocField(ParentUNID;"DateList")[itemKtr]) & @GetDocField(ParentUNID;"ActualHrsList")[itemKtr] = "-";
@Do(
varDelayCount := varDelayCount + 1;
varActualHrsList := varActualHrsList : varActualHrsList[itemKtr - 1];
varHMR_A := varHMR_A : "0";
varHMR_B := varHMR_B : "0";
varHMR_C := varHMR_C : "0";
varHMR_Total := varHMR_Total : "0";
varDiesel_A := varDiesel_A : "0";
varDiesel_B := varDiesel_B : "0";
varDiesel_C := varDiesel_C : "0";
varDiesel_Total := varDiesel_Total : "0";
varRemarksList := varRemarksList : "-";
varRemarksList_A := varRemarksList_A : "-";
varRemarksList_B := varRemarksList_B : "-";
varRemarksList_C := varRemarksList_C : "-";
varOperatorList_A := varOperatorList_A : "-";
varOperatorList_B := varOperatorList_B : "-";
varOperatorList_C := varOperatorList_C : "-";
varTestList_A := varTestList_A : "-";
varTestList_B := varTestList_B : "-";
varTestList_C := varTestList_C : "-"
);
@Do(
varActualHrsList := varActualHrsList : @GetDocField(ParentUNID;"ActualHrsList")[itemKtr];
varHMR_A := varHMR_A : @GetDocField(ParentUNID;"Machine_Run_Time_A")[itemKtr];
varHMR_B := varHMR_B : @GetDocField(ParentUNID;"Machine_Run_Time_B")[itemKtr];
varHMR_C := varHMR_C : @GetDocField(ParentUNID;"Machine_Run_Time_C")[itemKtr];
varHMR_Total := varHMR_Total : @GetDocField(ParentUNID;"Machine_Run_Time_Total")[itemKtr];
varDiesel_A := varDiesel_A : @GetDocField(ParentUNID;"DieselConsumedListShiftA")[itemKtr];
varDiesel_B := varDiesel_B : @GetDocField(ParentUNID;"DieselConsumedListShiftB")[itemKtr];
varDiesel_C := varDiesel_C : @GetDocField(ParentUNID;"DieselConsumedListShiftC")[itemKtr];
varDiesel_Total := varDiesel_Total : @GetDocField(ParentUNID;"DieselConsumedListTotal")[itemKtr];
varRemarksList := varRemarksList : @GetDocField(ParentUNID;"RemarksList")[itemKtr];
varRemarksList_A := varRemarksList_A : @GetDocField(ParentUNID;"RemarksListA")[itemKtr];
varRemarksList_B := varRemarksList_B : @GetDocField(ParentUNID;"RemarksListB")[itemKtr];
varRemarksList_C := varRemarksList_C : @GetDocField(ParentUNID;"RemarksListC")[itemKtr];
varOperatorList_A := varOperatorList_A : @GetDocField(ParentUNID;"OperatorListA")[itemKtr];
varOperatorList_B := varOperatorList_B : @GetDocField(ParentUNID;"OperatorListB")[itemKtr];
varOperatorList_C := varOperatorList_C : @GetDocField(ParentUNID;"OperatorListC")[itemKtr];
varTestList_A := varTestList_A : @GetDocField(ParentUNID;"TestListA")[itemKtr];
varTestList_B := varTestList_B : @GetDocField(ParentUNID;"TestListB")[itemKtr];
varTestList_C := varTestList_C : @GetDocField(ParentUNID;"TestListC")[itemKtr]
)
)
);
varExtendedDate := @TextToTime(varDateList[@Elements(varDateList)]);
@For(delayKtr := 1; delayKtr <= varDelayCount; delayKtr := delayKtr + 1;
@Do(
varExtendedDate := @Adjust(varExtendedDate;0;0;1;0;0;0);
varExtendedDate := @If(@Weekday(varExtendedDate) = 1;@Adjust(varExtendedDate;0;0;1;0;0;0);varExtendedDate);
varSeqNoList := varSeqNoList : @Text(@Elements(varSeqNoList) + 1);
varDateList := varDateList : @Text(varExtendedDate);
varPlannedHrsList := varPlannedHrsList : "-";
varActualHrsList := varActualHrsList : "-";
varHMR_A := varHMR_A : "-";
varHMR_B := varHMR_B : "-";
varHMR_C := varHMR_C : "-";
varHMR_Total := varHMR_Total : "-";
varDiesel_A := varDiesel_A : "-";
varDiesel_B := varDiesel_B : "-";
varDiesel_C := varDiesel_C : "-";
varDiesel_Total := varDiesel_Total : "-";
varRemarksList := varRemarksList : "-";
varRemarksList_A := varRemarksList_A : "-";
varRemarksList_B := varRemarksList_B : "-";
varRemarksList_C := varRemarksList_C : "-";
varOperatorList_A := varOperatorList_A : "-";
varOperatorList_B :=varOperatorList_B : "-";
varOperatorList_C := varOperatorList_C : "-";
varTestList_A := varTestList_A : "-";
varTestList_B :=varTestList_B : "-";
varTestList_C := varTestList_C : "-"
)
);
@SetDocField(ParentUNID;"Total_Vehicle_Hours";@Sum(lkpResult));
delayHrsTotal := @If(@GetDocField(ParentUNID;"DelayHrs") = "";0;@TextToNumber(@GetDocField(ParentUNID;"DelayHrs")));
delayHrsTotal := delayHrsTotal + varDelayCount*Milage_Plan;
@SetDocField(ParentUNID;"DelayHrs";@Text(delayHrsTotal));
@SetDocField(ParentUNID;"SerialNoList";varSeqNoList);
@SetDocField(ParentUNID;"DateList";varDateList);
@SetDocField(ParentUNID;"PlannedHrsList";varPlannedHrsList);
@SetDocField(ParentUNID;"ActualHrsList";varActualHrsList);
@SetDocField(ParentUNID;"Machine_Run_Time_A";varHMR_A);
@SetDocField(ParentUNID;"Machine_Run_Time_B";varHMR_B);
@SetDocField(ParentUNID;"Machine_Run_Time_C";varHMR_C);
@SetDocField(ParentUNID;"Machine_Run_Time_Total";varHMR_Total);
@SetDocField(ParentUNID;"DieselConsumedListShiftA";varDiesel_A);
@SetDocField(ParentUNID;"DieselConsumedListShiftB";varDiesel_B);
@SetDocField(ParentUNID;"DieselConsumedListShiftC";varDiesel_C);
@SetDocField(ParentUNID;"DieselConsumedListTotal";varDiesel_Total);
@SetDocField(ParentUNID;"RemarksList";varRemarksList);
@SetDocField(ParentUNID;"RemarksListA";varRemarksList_A);
@SetDocField(ParentUNID;"RemarksListB";varRemarksList_B);
@SetDocField(ParentUNID;"RemarksListC";varRemarksList_C);
@SetDocField(ParentUNID;"OperatorListA";varOperatorList_A);
@SetDocField(ParentUNID;"OperatorListB";varOperatorList_B);
@SetDocField(ParentUNID;"OperatorListC";varOperatorList_C);
@SetDocField(ParentUNID;"TestListA";varTestList_A);
@SetDocField(ParentUNID;"TestListB";varTestList_B);
@SetDocField(ParentUNID;"TestListC";varTestList_C);
@SetDocField(ParentUNID;"Meter_Changed_At_HMR";meter_Change_HMR_Reading)
)
);
@For(tmpKtr := 1; tmpKtr <= @Elements(componentsUNID);tmpKtr := tmpKtr + 1;
@Do(
totalHRS := @TextToNumber(@GetDocField(componentsUNID[tmpKtr];"Total_Component_Hours"));
targetRun := @TextToNumber(@GetDocField(componentsUNID[tmpKtr];"Component_Target_HMR"));
FailedFlag := @GetDocField(componentsUNID[tmpKtr];"FailedFlag");
fitmentDate := @GetDocField(componentsUNID[tmpKtr];"Fitment_Date");
component_Starting_HMR := @GetDocField(componentsUNID[tmpKtr];"Starting_HMR");
@If(targetRun > totalHRS & fitmentDate <= Log_Date & FailedFlag != "Yes";
@Do(
logDates := @Implode(@GetDocField(componentsUNID[tmpKtr];"Log_Dates");",");
shift1Runs := @Implode(@GetDocField(componentsUNID[tmpKtr];"Shift1_Runs");",");
shift2Runs := @Implode(@GetDocField(componentsUNID[tmpKtr];"Shift2_Runs");",");
shift3Runs := @Implode(@GetDocField(componentsUNID[tmpKtr];"Shift3_Runs");",");
shift1Diesel := @Implode(@GetDocField(componentsUNID[tmpKtr];"Shift1_Diesel");",");
shift2Diesel := @Implode(@GetDocField(componentsUNID[tmpKtr];"Shift2_Diesel");",");
shift3Diesel := @Implode(@GetDocField(componentsUNID[tmpKtr];"Shift3_Diesel");",");
shift1Remarks := @Implode(@GetDocField(componentsUNID[tmpKtr];"RemarksA");",");
shift2Remarks := @Implode(@GetDocField(componentsUNID[tmpKtr];"RemarksB");",");
shift3Remarks := @Implode(@GetDocField(componentsUNID[tmpKtr];"RemarksC");",");
plannedHrsListCompleted := @Implode(@GetDocField(componentsUNID[tmpKtr];"PlannedHrsListCompleted");",");
actualHrsListCompleted := @Implode(@GetDocField(componentsUNID[tmpKtr];"ActualHrsListCompleted");",");
hrsInShift1 := 0;
hrsInShift2 := 0;
hrsInShift3 := 0;
@If(@Trim(shift1Runs) != "";
@Do(
hrsInShift1 := shift_A_Run;
hrsInShift2 := shift_B_Run;
hrsInShift3 := shift_C_Run;
logDates := @Explode(logDates + "," + @Text(@Date(@GetField("Log_Date")));",");
shift1Runs := @Explode(shift1Runs + "," + @Text(shift_A_Run);",");
shift2Runs := @Explode(shift2Runs + "," + @Text(shift_B_Run);",");
shift3Runs := @Explode(shift3Runs + "," + @Text(shift_C_Run);",");
shift1Diesel := @Explode(shift1Diesel + "," + @If(@Text(Diesel_A) = "";"0";@Text(Diesel_A));",");
shift2Diesel := @Explode(shift2Diesel + "," + @If(@Text(Diesel_B) = "";"0";@Text(Diesel_B));",");
shift3Diesel := @Explode(shift3Diesel + "," + @If(@Text(Diesel_C) = "";"0";@Text(Diesel_C));",");
shift1Remarks := @Explode(shift1Remarks + "," + @If(@Trim(Remarks_A) = "";"-";@Text(Remarks_A));",");
shift2Remarks := @Explode(shift2Remarks + "," + @If(@Trim(Remarks_B) = "";"-";@Text(Remarks_B));",");
shift3Remarks := @Explode(shift3Remarks + "," + @If(@Trim(Remarks_C) = "";"-";@Text(Remarks_C));",");
plannedHrsListCompleted := @Explode(plannedHrsListCompleted + "," + @Text(Cumulative_Vehicle_Reading_Plan + Milage_Plan);",");
actualHrsListCompleted := @Explode(actualHrsListCompleted + "," + @Text(HMR_End_Reading);",")
);
@Do(
logDates := @Text(@Date(@GetField("Log_Date")));
@If(HMR_Start_Reading + shift_A_Run >= component_Starting_HMR;
@Do(
hrsInShift1 := HMR_Start_Reading + shift_A_Run - component_Starting_HMR;
shift1Runs := @Text(hrsInShift1);
shift1Diesel := @If(@Text(Diesel_A) = "";"0";@Text(Diesel_A));
shift1Remarks := @If(@Trim(@Text(Remarks_A)) = "";"-";@Text(Remarks_A))
);
@Do(
shift1Runs := "0";
shift1Diesel := "0";
shift1Remarks := "-"
)
);

@If(HMR_Start_Reading + shift_A_Run + shift_B_Run >= component_Starting_HMR;
@Do(
hrsInShift2 := HMR_Start_Reading + shift_A_Run + shift_B_Run - component_Starting_HMR - hrsInShift1;
shift2Runs := @Text(hrsInShift2);
shift2Diesel := @If(@Text(Diesel_B) = "";"0";@Text(Diesel_B));
shift2Remarks := @If(@Trim(@Text(Remarks_B)) = "";"-";@Text(Remarks_B))
);
@Do(
shift2Runs := "0";
shift2Diesel := "0";
shift2Remarks := "-"
)
);
@If(HMR_Start_Reading + shift_A_Run + shift_B_Run + shift_C_Run >= component_Starting_HMR;
@Do(
hrsInShift3 := HMR_Start_Reading + shift_A_Run + shift_B_Run + shift_C_Run - component_Starting_HMR - hrsInShift1 - hrsInShift2;
shift3Runs := @Text(hrsInShift3);
shift3Diesel := @If(@Text(Diesel_C) = "";"0";@Text(Diesel_C));
shift3Remarks := @If(@Trim(@Text(Remarks_C)) = "";"-";@Text(Remarks_C))
);
@Do(
shift3Runs := "0";
shift3Diesel := "0";
shift3Remarks := "-"
)
);
plannedHrsListCompleted := @Text(Cumulative_Vehicle_Reading_Plan + Milage_Plan);
actualHrsListCompleted := @Text(HMR_End_Reading)
)
);
@SetDocField(componentsUNID[tmpKtr];"Total_Component_Hours";@Text(totalHRS + hrsInShift1 + hrsInShift2 + hrsInShift3));
@SetDocField(componentsUNID[tmpKtr];"Log_Dates";logDates);
@SetDocField(componentsUNID[tmpKtr];"Shift1_Runs";shift1Runs);
@SetDocField(componentsUNID[tmpKtr];"Shift2_Runs";shift2Runs);
@SetDocField(componentsUNID[tmpKtr];"Shift3_Runs";shift3Runs);
@SetDocField(componentsUNID[tmpKtr];"Shift1_Diesel";shift1Diesel);
@SetDocField(componentsUNID[tmpKtr];"Shift2_Diesel";shift2Diesel);
@SetDocField(componentsUNID[tmpKtr];"Shift3_Diesel";shift3Diesel);
@SetDocField(componentsUNID[tmpKtr];"RemarksA";shift1Remarks);
@SetDocField(componentsUNID[tmpKtr];"RemarksB";shift2Remarks);
@SetDocField(componentsUNID[tmpKtr];"RemarksC";shift3Remarks);
@SetDocField(componentsUNID[tmpKtr];"PlannedHrsListCompleted";plannedHrsListCompleted);
@SetDocField(componentsUNID[tmpKtr];"ActualHrsListCompleted";actualHrsListCompleted)
);
""
)
)
);
varTotalHMR_Before := Cumulative_Vehicle_Hours - Day_Run_Mileage;
varTotalHMR_After := Cumulative_Vehicle_Hours;
varServiceDueHrs := @GetDocField(ParentUNID;"Service_Alert_At_HMRs");
varSendMailFlag := 0;
@For(itemsKtr := 1; itemsKtr <= @Elements(varServiceDueHrs) & varSendMailFlag = 0;itemsKtr := itemsKtr + 1;
@Do(
currValue := @TextToNumber(varServiceDueHrs[itemsKtr]);
@If(currValue <= 20 & varTotalHMR_Before = 0;
varSendMailFlag := 1;
@Modulo(varTotalHMR_Before;currValue) < (currValue - 20) &     @Modulo(varTotalHMR_After;currValue) >= (currValue - 20);
varSendMailFlag := 1;
""
)
)
);
@If(varSendMailFlag = 1;
@Do(
varSendTo := T_And_D_Managers : T_And_D_Engineers;
varSubject := "[Daily Log System]: Machine Due For Service";
varBody := "Service is due for machine:: " + Machine_ID;
@MailSend(varSendTo;"";"";varSubject;"";varBody;0);
@Prompt([Ok];"Notification";"Notificaton `about` Service")
);
""
)
);"")

Thanks

1
One thing to note is, the code is working fine in normal condition. The problem comes, when the no. of related documents are very high. - Romil Handoo
Most probably there is an infinite loop somewhere, or you concatenate values to a list that grows toolarge (e.g. by using the permutation operator *+). This for sure is an error in your code, as processing 100 documents is not a problem at all in Formula language. Without code nobody can help. In this form I voted to close with the reason "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it" - Torsten Link
Please go through the code. I can't understand why the code fails. May be because of the length of 'Remarks' values, which is being appended in a variable. - Romil Handoo
It might be one of your implode/explode operations, when the string gets too long or there are too many elements in it. IMHO you'd better rewrite your code in LotusScript, it should be a lot easier and more readable. - D.Bugger
And just a warning: if you ever have to make a copy of the database, it won't work, because all your relations depend on UNIDs... - D.Bugger

1 Answers

0
votes

Got the cause of the error.

Following line raises exception as the length of string exceeds allowed limit:

**shift1Remarks := @Implode(@GetDocField(componentsUNID[tmpKtr];"RemarksA");",");

............

............

shift1Remarks := @Explode(shift1Remarks + "," + @If(@Trim(Remarks_A) = "";"-";@Text(Remarks_A));",");**

Modified these lines. Modified code is below:

**shift1Remarks := @GetDocField(componentsUNID[tmpKtr];"RemarksA");

............

............

shift1Remarks := shift1Remarks : @If(@Trim(Remarks_A) = "";"-";@Text(Remarks_A));**

Thanks