When adding code to the OnValidate trigger on a page, why is the trigger getting executed twice?
vimo
Member Posts: 14
Hello! I am running into an issue that I hope someone can help me with. I am using NAV 2016. In my List page, I have added some code to validate that two fields match. If they do not match, the code gives the user a message letting them know that the two fields must match.
It is working fine accept that the message box pops up twice. The first time it opens, I select OK, and then it opens up a second time.
Here is the code:
Batch - OnValidate()
IF "Order Lines" <> "Lines Shipped" THEN BEGIN
MESSAGE('The number of Order Lines must Match the number of Lines Shipped');
"Ready for Batch" := FALSE;
CurrPage.UPDATE;
END;
Is there a way to make the code only run once?
Thanks in advance!
It is working fine accept that the message box pops up twice. The first time it opens, I select OK, and then it opens up a second time.
Here is the code:
Batch - OnValidate()
IF "Order Lines" <> "Lines Shipped" THEN BEGIN
MESSAGE('The number of Order Lines must Match the number of Lines Shipped');
"Ready for Batch" := FALSE;
CurrPage.UPDATE;
END;
Is there a way to make the code only run once?
Thanks in advance!
0
Best Answer
-
move this code to the table OnValidate trigger and change MESSAGE function to the ERROR:
IF "Order Lines" <> "Lines Shipped" THEN ERROR('The number of Order Lines must Match the number of Lines Shipped');
you dont need all other lines.
But you have to add one more condition before raising the error, like this:IF "Ready for Batch" AND ("Order Lines" <> "Lines Shipped") THEN ERROR('The number of Order Lines must Match the number of Lines Shipped');6
Answers
-
move this code to the table OnValidate trigger and change MESSAGE function to the ERROR:
IF "Order Lines" <> "Lines Shipped" THEN ERROR('The number of Order Lines must Match the number of Lines Shipped');
you dont need all other lines.
But you have to add one more condition before raising the error, like this:IF "Ready for Batch" AND ("Order Lines" <> "Lines Shipped") THEN ERROR('The number of Order Lines must Match the number of Lines Shipped');6 -
Thank you kvb! This worked great!1
-
Hi logger!
When I changed the code to use the Error function, I no longer needed the rest of the code. It automatically unchecked the box.
to answer your question, I was using it with my original code to show that the checkbox was unchecked.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