Delete a record when validate a field

Alkro
Member Posts: 115
I don't know if is possible this:
I have a list Form. One field called Exclude is editable (Text 50) and in OnValidate for this field in the Form is called a new Function.
This Function is in the Table with a local variable to the same Table (lvrec). This function do this:
Primary Key in table is "Document No.", "Line No."
lvrec.RESET;
lvrec.SETRANGE("Document No.", DocNo);
lvrec.DELETEALL;
When i input a value in Exclude field in Form, records for the same Document No. are deleted but give this error:
The Sale Detail does not exist.
Identification fields and values:
Document No.='DOC0001',Line No.='10000'
I try CurrForm.UPDATE, RESET... But anything is wrong recovering form record...
Any solution?
I have a list Form. One field called Exclude is editable (Text 50) and in OnValidate for this field in the Form is called a new Function.
This Function is in the Table with a local variable to the same Table (lvrec). This function do this:
Primary Key in table is "Document No.", "Line No."
lvrec.RESET;
lvrec.SETRANGE("Document No.", DocNo);
lvrec.DELETEALL;
When i input a value in Exclude field in Form, records for the same Document No. are deleted but give this error:
The Sale Detail does not exist.
Identification fields and values:
Document No.='DOC0001',Line No.='10000'
I try CurrForm.UPDATE, RESET... But anything is wrong recovering form record...
Any solution?
0
Answers
-
Try to analyze what is happening.
You have a code in OnValidate trigger. When you enter something on a form the form, at some point is supposed to update the record you have just changed. But before this happens the code on changed field deletes the record which is just about to be updated...Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
All this events occurs:
OnModify - Record
OnValidate - Form
Delete Function in Table
Is possible that OnModify is executed the last? In this case... There is no way to do it?0 -
Experiment by writing a small function in each trigger writing to some file the trigger and the current object name, and the timestamp. In a pattern: Open a file, write trigger+timestamp, close the file. This will give you a lot of insight on how the things are executed in NAV.
There is a way to do it.. or two. You do not have control over the order in which triggers are executed. But sometimes you can prevent the trigger from being executed. For example by changing the design and avoid modification of the record just before it is supposed to be deleted.
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Your code tries to MODIFY a record that you deleted first, so that error message is expected.
Start by explaining in regular words what you want to accomplish.0 -
Good guys wanna teach you how to fish but you want only the fish itself and want it fast, right?)
I suggest you to run your function not on the OnValidate trigger but on the Button OnRun trigger
Dont forget to update from after0
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
- 320 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