Error when Posting more than once on a Form

niimodinniimodin Member Posts: 142
Hello Experts,
I am developing a payroll solution for my client.
I have a form for calculating the Loan monthly repayment for the employees.
When I calculate and post a loan and then try to another without closing the form I receive this message:

"Loan Repayment Schedule Entry No 18 already exists"

However it works perfectly when the form is close before doing the next transaction.

Can anyone help?

My code is below
IF NOT CONFIRM(Text000,FALSE) THEN
  EXIT;

LoanID := STRSUBSTNO('%1/%2/%3/%4',"No.",LoanSchemes.Code,StartingMonth,StartingYear);

IF Status = Status::Active THEN BEGIN

    WITH LoanScheduler DO BEGIN
        INIT;
        "Staff ID" := "No.";
        "Loan ID" := LoanID;
        "Starting Month" :=Month;
        "Starting Year" := StartingYear;
        Principal := "Loan Amount";
        "Monthly Payment" := LoanCalculator.LoanCalculator("Loan Amount","Annual Interest Rate"/100,
                                                            "Repayment Period",NoofRepayment);
        "Ending Month" := EndingMonth;
        "Ending Year" := EndingYear;
        "Outstanding Amount" := "Total Amount to be Paid";
        "Transaction Date/Time" := CREATEDATETIME(TODAY,TIME);
        "User ID" := USERID;
        StartingMonthInteger := MonthBuffer.ReverseMonthCalculator(Month);
        LoanScheduler.EndingMonthInteger := MonthBuffer.ReverseMonthCalculator(EndingMonth);
        "Approved By" := "Approved By";
        "Annual Interest Rate (%)" := "Annual Interest Rate";
        "Loan Repayment Period" := "Repayment Period";
        "No. of Payment in a Year" := NoofRepayment;
        "Approved By" := ApprovedBy;
        "Total Repayment Amount" := "Total Amount to be Paid";
        "Loan Code" := LoanSchemes.Code;
        LoanScheduler.Description := "Loan Name";
        LoanScheduler."Total Interest to be Paid" := "Total Interest Amount";
        INSERT;
    END;

END;


"Loan Amount" := 0;
ApprovedBy := '';
"Annual Interest Rate" := 0 ;
"Repayment Period" := 0;
NoofRepayment := 0;
ApprovedBy := '';
LoanSchemes.Code := '';
BasicSalary := 0;
"Loan Name" := '';
StartingMonth := StartingMonth::" ";

Calculator;

Comments

  • SogSog Member Posts: 1,023
    remember how init doesn't initiate primary key fields?
    perhaps a findlast or getnextentryno function would do the trick with the entry no.
    Example
    These C/AL examples show how to use the INIT function. Assume that the primary key includes the "No." field:

    Scenario 1
    Customer.INIT;
    Customer."No." := '1120';
    Customer.INSERT;

    Scenario 2
    Customer."No." := '1120';
    Customer.INIT;
    Customer.INSERT;

    Since INIT does not initialize the primary key fields, the order of the statements in situation 1 and 2 is not important. Situation 1 causes the same result as situation 2.
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • niimodinniimodin Member Posts: 142
    Thank you very much

    I added a the FINDLAST and it worked


    INIT;
    
    IF FINDLAST THEN BEGIN
      "Entry No" := "Entry No"+1;
    END;
    
    "Staff ID" := "No.";
    
Sign In or Register to comment.