payMonthYear := FORMAT(RunDate,0,'<Month text> <Year4>'); history.SETRANGE(empid,employee."No."); history.SETRANGE(MonthYear,payMonthYear); IF NOT history.FINDLAST THEN BEGIN // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ { payMonthYear := FORMAT(RunDate,0,'<Month text> <Year4>'); // message(payMonthYear); hisVal.SETRANGE(empid,loan.empid); hisVal.SETRANGE(MonthYear,payMonthYear); // message(hisVal.MonthYear); //IF NOT hisVal.FINDFirst THEN BEGIN } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Save the last ID of table History (I suppose it is unique) history.RESET; IF history.FINDLAST THEN LintHistory_ID := history.id; loan.RESET; //loan.SETCURRENTKEY("Freeze Loan",balance); loan.SETRANGE("Freeze Loan",FALSE); loan.SETFILTER(balance,'>0'); IF loan.FINDSET(TRUE,TRUE) THEN // TRUE,TRUE because you want to change the table REPEAT loan2 := loan; // if you change records inside a loop, you NEED a second variable in which you change the record op_bal := loan2.balance; cl_bal := loan2.balance - loan2.monthly_pay; paidoff := loan2.loan_amount - cl_bal; loan2.paidoffamount := paidoff; loan2.balance := cl_bal; loan2.MODIFY; // no need for 2 modifies of the same table //insert into loan history table. LintHistory_ID += 1; CLEAR(history); history.id := LintHistory_ID; history.op_balance := op_bal; history.cl_balance := cl_bal; history.ded_amount := loan2.monthly_pay; history.int_amount := loan2.monthly_int; history.loan_id := loan2.id; history.empid := loan2.empid; history."Run Date" := RunDate; history.MonthYear :=FORMAT(RunDate,0,'<Month text> <Year4>'); history.INSERT(FALSE); // the record doesn't exist, so you need to INSERT it and not MODIFY it UNTIL loan.NEXT = 0; //END ELSE BEGIN //MESSAGE('Loan already Process for the Month of: '+'%1',payMonthYear); //exit; //CurrReport.SKIP; //display result on a report view.RUN; //END; END ELSE BEGIN ERROR('This month loan has already been process'); END;
Comments
which message are you expecting ?
is it the
ERROR('This month loan has already been process');
Have you tried using the debugger?
Dynamics Nav Add-ons
http://www.simplydynamics.ie/Addons.html
So you would use IF & GET if it GET's it then it already exists and your message telling you it already exists will pop-up.
Would you like to overwrite (dialog) if yes then map your fields then end in (MODIFY) if no EXIT.
If the get does not find a match - you will map your fields & use (INSERT)
hope that make sence.
http://www.BiloBeauty.com
http://www.autismspeaks.org