Error message on Running a report

asemberengasembereng Member Posts: 220
I have written a report two days ago and it was working fine but all of a sudden i had this error message "the History does not exist Identification fields and values: id='0' empid= 'pc001'. Below is my code.. Any idea what went wrong?
Documentation()

Employee - OnPreDataItem()
IF RunDate = 0D THEN
ERROR('Must enter run date');
EXIT;

Employee - OnAfterGetRecord()
IF Employee.Status=Employee.Status::Active THEN BEGIN
// Set, check and skip already generated payslips.
  payMonthYear := FORMAT(RunDate,0,'<Month text> <Year4>');
  hisVal.SETRANGE(empid,"No.");
  hisVal.SETRANGE(MonthYear,payMonthYear);
  IF NOT hisVal.FIND('-') THEN BEGIN

    // Initialize vars
    taxableAllowance := 0;
    globalBasicPay := 0;
    totalallowance := 0;
    totalDed := 0;
    ded_loan :=0;
    net := 0;
    basic := 0;
    npf := 0;
    tax := 0;
    icfhis:=0;
    npf_conthis:=0;
    ded_int:=0;
    // End of inititalization.

          IF his.FIND('+') THEN BEGIN
              NextLineNo := his.id + 1;
              his.id := NextLineNo;
          END;
    his.INSERT;

    Allowance.RESET;
    Allowance.SETRANGE(empid,"No.");
        IF Allowance.FINDSET THEN BEGIN
          REPEAT
                extraPyMod.GET(Allowance."pay model");
                IF (Allowance."from date"<= RunDate) AND (Allowance."to date">=RunDate)
                AND(extraPyMod.tax = FALSE) AND (Allowance.Amount > 0) THEN BEGIN
                  totalallowance += Allowance.Amount;
                END ELSE IF (Allowance."from date"<= RunDate) AND (Allowance."to date">=RunDate)
                AND(extraPyMod.tax = TRUE) AND (Allowance.Amount > 0)  THEN BEGIN
                  taxableAllowance += Allowance.Amount;   
                END ELSE IF (Allowance."from date"<= RunDate) AND (Allowance."to date">=RunDate)
                AND (extraPyMod.tax = FALSE) AND (Allowance.Amount < 0) THEN BEGIN
                 totalDed += ABS(Allowance.Amount);
              {  END ELSE IF (Allowance."from date"<= RunDate) AND (Allowance."to date">=RunDate)
                AND(extraPyMod.fringes = TRUE) AND (Allowance.Amount > 0)  THEN BEGIN
                  totfringes += Allowance.Amount* 0.25; }
                END;



         UNTIL Allowance.NEXT = 0;
    END;

    //==================================================================================
    //loan.GET(Employee."No.");
    loan.RESET;
    loan.SETRANGE(empid,"No.");
        IF loan.FINDSET THEN BEGIN
          REPEAT
            IF (loan.monthly_pay>0)  THEN BEGIN
              ded_loan +=loan.monthly_pay;
              ded_int+=loan.monthly_int;
            END;

          UNTIL loan.NEXT = 0;
       END;




    //==================================================================================

    // get basic pay for wages, monthly globalBasicPay and annual as well
    basic := BasicSal;
    npf := basic * 0.05;
    IF (basic >=1500) THEN
       icfhis := 15
    ELSE
       icfhis := basic * 0.01;
    npf_conthis:=0.1 * BasicSal;




    // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // income tax algorithm

    taxa := 83.33;
    taxb := 207.67;
    taxc := 374.58;
    taxd := 583.33;
    taxe := 2153.08;

    incomea := 625;
    incomeb := 1458;
    incomeg := 1455;
    incomec := 2288;
    incomed := 3123;
    incomee := 3958;
    incomef := 8443;

    globalBasicPay := basic + taxableAllowance;


    // -----------------------------------------------------------------------------------------------------

        IF (globalBasicPay <= incomea) THEN
        tax := 0
        ELSE IF (globalBasicPay <= incomeg) AND (globalBasicPay > incomea) THEN
        tax := (ROUND((globalBasicPay-incomea),5,'>') * 0.1)


        ELSE IF (globalBasicPay <= incomeb) AND (globalBasicPay > incomeg) THEN
        tax := taxa



        ELSE IF (globalBasicPay <= incomec) AND (globalBasicPay > incomeb) THEN
        tax := (ROUND((globalBasicPay-incomeb),5,'>') * 0.15) + taxa



        ELSE IF (globalBasicPay <= incomed) AND (globalBasicPay > incomec) THEN
        tax := (ROUND((globalBasicPay-incomec),5,'>') * 0.2)+ taxb



        ELSE IF (globalBasicPay <= incomee) AND (globalBasicPay > incomed) THEN
        tax := (ROUND((globalBasicPay-incomed),5,'>') * 0.25)+ taxc



        ELSE IF (globalBasicPay >= incomee)  AND (globalBasicPay < incomef) THEN
        tax := (ROUND((globalBasicPay-incomee),5,'>') * 0.35)+ taxd

        ELSE IF (globalBasicPay > incomef) THEN
        tax := ((globalBasicPay-incomef) * 0.35)+ taxe ;





    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    net := globalBasicPay + totalallowance - npf - tax - totalDed- ded_loan-ded_int;

    {Messages for values...
    MESSAGE('Showing values: '+'%1\'+'%2\'+'%3\'+'%4\'+'%5\'+'%6\'+'%7\',basic,globalBasicPay,tax,npf,net,totalallowance,totalDed);
    MESSAGE('Taxable Allowance: '+'%1',taxableAllowance);
    End of messages for values. }

    // Assigning all values here:
    his.reset;
    his.empid := "No.";
    his."Date Run" := RunDate;
    his."basic pay" := basic;
    his.npf := npf;
    his.i_tax := tax;
    his.net := net;
    his.sum_all := totalallowance + taxableAllowance;
    his.sum_ded := totalDed;
    his.sum_loan := ded_loan;
    his.sum_int:=ded_int;
    his.icf:=icfhis;
    his.npf_cont:=npf_conthis;
    his.department := department;
    his."Bank Name" := "Bank Name";
    his.Branch := "Bank Branch";
    his.Name := "First Name" + ' ' + "Middle Name" +' ' + "Last Name";
    his."Account No." := "Account No.";
    his."taxable pay" := globalBasicPay;
    his."pay mode" := "pay mode";
    his."sum taxable allowance" := taxableAllowance;
    //his.fringes := totfringes;

    his.MonthYear := FORMAT(RunDate,0,'<Month text> <Year4>');
    // Implementing data.
    his.MODIFY;
    END ELSE BEGIN
    MESSAGE('Payslip already exist for employee: '+'%1',"No.");
    CurrReport.SKIP;
    END;

END;

Employee - OnPostDataItem()

GetNextLine(his : Record History) : Integer

Comments

  • kinekine Member Posts: 12,562
    And on which line this error is? Did you tried to enable debugger and see where it stops?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    I'm sure the error comes at this line:
    his.MODIFY;
    

    And when i see you source ..... oh .......

    At the top you insert a "His" record when you doesn't find the last
    IF his.FIND('+') THEN BEGIN
                  NextLineNo := his.id + 1;
                  his.id := NextLineNo;
              END;
    his.INSERT; //<---- this insert ever(!) a rec in the his table
    

    Then, at the end you reset the His table and modify it.
    his.reset;
    his.empid := "No.";  //the second part of the primary key
    ....
    ....
    his.modify;  //NAV will now update the record with ID 0 and empid = pc001. But this record doesn't exist
    

    Why? What do you wish to do with the report?

    Regards
    Do you make it right, it works too!
  • asemberengasembereng Member Posts: 220
    All i want the report to do is get data from the employee table, perform some calculations and dump the data into the table called history. and history has a field ID that should auto increment.
    How best do you think this can be achieved?
    Thank you
Sign In or Register to comment.