Problem with the WITH DO clause
TheKoori
Member Posts: 3
Hi
I had a strange problem today, with some previously working code, that wasn't made by me.
Without changing anything, some code just stopped working after i compiled the codeunit container it.
I have simplified the code, just to give you an idea, of what i was up against.
GlobalLotNo is a global variable, LotNo is a parameter in the function AssignLot, and the record Parameter "Order", contains a field called LotNo.
Previously, the GlobalLotNo would be assigned the value of LotNo (in this case '0001'). But now NAV uses the Order.LotNo instead, which in this case is blank.
The debugger doesn't know this, because it keeps displaying '0001' in LotNo (it thinks it is the parameter, and not the field.) (Yes, the debugger is not that clever, I know
)
I can see why this is bad code, and you should not have a parameter called exactly the same as a field within a WITH DO clause.
But did the interpretation of this code change in some version of the NAV client ?
Please don't mind the code as much, because it is very simplified, I know this does absolutely nothing meaningful
OnRun()
AssignLot(OrderPending,'0001');
AssignLot(Order : Record "Order Request Pending";LotNo : Code[20])
WITH Order DO BEGIN
GlobalLotNo := LotNo;
END;
Best Regards
Thomas Korsgaard
I had a strange problem today, with some previously working code, that wasn't made by me.
Without changing anything, some code just stopped working after i compiled the codeunit container it.
I have simplified the code, just to give you an idea, of what i was up against.
GlobalLotNo is a global variable, LotNo is a parameter in the function AssignLot, and the record Parameter "Order", contains a field called LotNo.
Previously, the GlobalLotNo would be assigned the value of LotNo (in this case '0001'). But now NAV uses the Order.LotNo instead, which in this case is blank.
The debugger doesn't know this, because it keeps displaying '0001' in LotNo (it thinks it is the parameter, and not the field.) (Yes, the debugger is not that clever, I know
I can see why this is bad code, and you should not have a parameter called exactly the same as a field within a WITH DO clause.
But did the interpretation of this code change in some version of the NAV client ?
Please don't mind the code as much, because it is very simplified, I know this does absolutely nothing meaningful
OnRun()
AssignLot(OrderPending,'0001');
AssignLot(Order : Record "Order Request Pending";LotNo : Code[20])
WITH Order DO BEGIN
GlobalLotNo := LotNo;
END;
Best Regards
Thomas Korsgaard
0
Comments
-
I think that it was changed, but I do not know in which version. I just know that I already met this...0
-
That's another good reason why I always say Fields have to be named like "Lot No." and Variables have to be named like LotNo. When you set the cursor on the name in code you'll get a hint in the status bar what it is that you are focussing. (There are some limitation to this but in most of the cases it's enough.)"Money is likewise the greatest chance and the greatest scourge of mankind."0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
