Navision treating my boolean as false!

SilentDSilentD 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:
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.

Comments

  • SavatageSavatage Member Posts: 7,142
    BEGIN
      message('%1',UserPostVal2); <<<<--add this
      IF UserPostVal2 THEN
      BEGIN
    

    make absolutely sure it TRUE
  • kinekine Member Posts: 12,562
    Have you checked that there is no global and local variable with same name? ;-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SilentDSilentD Member Posts: 6
    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.
  • kinekine Member Posts: 12,562
    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...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • SilentDSilentD Member Posts: 6
    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. :-k
  • garakgarak Member Posts: 3,263
    edited 2008-12-09
    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!
  • SilentDSilentD Member Posts: 6
    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!
  • garakgarak Member Posts: 3,263
    So please and welcome
    Do you make it right, it works too!
  • kinekine Member Posts: 12,562
    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. :wink:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • garakgarak Member Posts: 3,263
    On Codeunits only for OnRun(VAR Rec : Record XYZ).
    Not for other functions with a VAR Table Parameter
    Do you make it right, it works too!
  • SilentDSilentD Member Posts: 6
    Good to know! It seems like it is out of scope but there's no changing it now. :-)
Sign In or Register to comment.