Navision treating my boolean as false!

SilentD
Member Posts: 6
I just had a client report that some posting security logic was no longer working after I updated a form. I traced it to the following code:
The problem was that the second test: IF UserPostVal2 THEN was always returning False even though the variable UserPostVal2 was True! I watched the value in the debugger which reported its value as Yes. I ended up having to create another variable to do the same task which worked. I've never seen Navision do this before. Kind of a bummer.
IF JobPostBypass THEN BEGIN IF UserPostVal2 THEN BEGIN CLEARALL; SetJobPostBypass := TRUE; JobPostBypass := TRUE; UserPostVal2 := TRUE; END ELSE BEGIN //JPB = TRUE, UPV = FALSE CLEARALL; SetJobPostBypass := TRUE; JobPostBypass := TRUE; END; END ELSE BEGIN IF UserPostVal2 THEN BEGIN CLEARALL; UserPostVal2 := TRUE; END ELSE //BOTH ARE FALSE CLEARALL; END;
The problem was that the second test: IF UserPostVal2 THEN was always returning False even though the variable UserPostVal2 was True! I watched the value in the debugger which reported its value as Yes. I ended up having to create another variable to do the same task which worked. I've never seen Navision do this before. Kind of a bummer.
0
Comments
-
BEGIN message('%1',UserPostVal2); <<<<--add this IF UserPostVal2 THEN BEGIN
make absolutely sure it TRUE0 -
Have you checked that there is no global and local variable with same name? ;-)0
-
I'll try that next time. What's odd is that I didn't touch this code with my last modification and it has been working perfectly for the past four months.0
-
Than I assume that there is same local and global var. It can start to do problems after recompilation. When there is only one variable (e.g. local), the compiled code is connected to this variable (through his ID). After someone add global variable with same name, the code can still use correct ID of the local variable. But when e.g. you import text file or you do some change which force NAV to totally recompile the object, it can take the global variable ID instead... - do not take it as fact, I didn't make any research if it is working in this way, but I know the situations, when two variables with same name started to work wrongly after some time of correct working...0
-
Sorry - I missed your post asking about variables with the same name. I just exported the codeunit to text and searched with a text editor. The variable name is unique. :-k0
-
Maybe a stupid question (hope this is not so in your table / function design).
But is there a field in this table or a function with the same name and Type / return Type?
Did you have test to change the name of the variable under your Globals? Can you compile or pops now up an error?
If no error pops up, then ther is a second variable, a field with the same name or a function with this name.Do you make it right, it works too!0 -
I think that's pretty close. The variable is unique within the codeunit (C90) but the codeunit OnRun local parameter Rec ("Purchase Header") variable does have a custom field by the same name. My code isn't inside of a WITH block so it still shouldn't be affected. But perhaps having a field within the TableNo of the codeunit that shares the same name as a global variable is a no-no.
Cheers!0 -
So please and welcomeDo you make it right, it works too!0
-
That the code is not within explicit with doesn't mean that you need to use Rec.xxx to address fields from the Rec variable. There is implicit "With Rec do" everywhere the Rec is used (forms, codeunit.OnRun etc.). And it is why it is not working.0
-
On Codeunits only for OnRun(VAR Rec : Record XYZ).
Not for other functions with a VAR Table ParameterDo you make it right, it works too!0 -
Good to know! It seems like it is out of scope but there's no changing it now. :-)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
- 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