validating data before writing them to a table
asembereng
Member Posts: 220
I have a history table but i want to validate whether the data already exists on that table before it writes to it. If it exists it ask you whether you want to reprocess it else it writes to it. Below is what i have written so far.. Can someone help me why is not displaying the message when it finds the record?
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;
0
Comments
-
Hi
which message are you expecting ?
is it the
ERROR('This month loan has already been process');
Have you tried using the debugger?0 -
Are you using Key's - that's what key's do. They allow data that's unique.
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.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 322 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions