...
AccCode := '';
CustLedgEntry.SETRANGE("Entry No.",Rec."Entry No.");
GenJnlLine.RESET;
GenJnlLine.SETRANGE("Journal Template Name",JnlTemplateName);
GenJnlLine.SETRANGE("Journal Batch Name",JnlBatchName);
// Delete the following line.
GenJnlLine.SETRANGE(GenJnlLine."Applies-to Doc. No.",Rec."Document No.");
RefPmtImportTemp.SETRANGE("Account No.",Rec."Account No.");
RefPmtImportTemp.SETRANGE("Filing Code",Rec."Filing Code");
// Delete the following lines.
IF (CustLedgEntry.FIND('-') AND (NOT GenJnlLine.FIND('-'))) OR
(NOT RefPmtImportTemp.FINDFIRST)
// End of the lines.
THEN BEGIN
GenJnlLine.INIT;
...
...
AccCode := '';
CustLedgEntry.SETRANGE("Entry No.",Rec."Entry No.");
GenJnlLine.RESET;
// Add the following line.
GenJnlLine.SETCURRENTKEY("Journal Template Name","Journal Batch Name","Applies-to Doc. No.","Reference No.");
GenJnlLine.SETRANGE("Journal Template Name",JnlTemplateName);
GenJnlLine.SETRANGE("Journal Batch Name",JnlBatchName);
// Add the following lines.
GenJnlLine.SETRANGE("Applies-to Doc. No.",Rec."Document No.");
GenJnlLine.SETRANGE("Reference No.",Rec."Reference No.");
// End of the lines.
RefPmtImportTemp.SETRANGE("Account No.",Rec."Account No.");
RefPmtImportTemp.SETRANGE("Filing Code",Rec."Filing Code");
// Add the following lines.
IF (CustLedgEntry.FIND('-') OR (NOT RefPmtImportTemp.FINDFIRST))
AND (NOT GenJnlLine.FIND('-'))
// End of the lines.
THEN BEGIN
GenJnlLine.INIT;
...