Global variable loosing value?

wilk_uwilk_u Member Posts: 94
Hey, I'm still learning this..
I defined a global variable in codeunit, assigned it a value in one function of that codeunit when launching a form, and in after validate trigger on that form i want to launch another function form that codeunit where i want to use value of my global variable, but its empty.
What's going on exactly? Only direct assignment operation on that variable is when I assign it a value in first function.
Regards.

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    I have created new codeunit with 2 functions
    set and get

    Set()
    Num := 1000;

    Get()
    MESSAGE('%1',Num);

    Num is a global variable of type integer..

    Created new form and called Set function onOpen form.

    Added a text field and called Get function OnAftervalidate of that field
    message showed 1000

    I didnt have any problem..
  • matttraxmatttrax Member Posts: 2,309
    Your Codeunit variable needs to be global as well.
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    wilk_u wrote:
    I defined a global variable in codeunit,
    Num is a global variable of type integer..
  • wilk_uwilk_u Member Posts: 94
    Maybe I'll be more specific
    Function executes after pressing button.
    Codeunit.Function(GivenRec);
    user selects record and then presses button.
    It operates on gl entries.
    Function goes like this:
    table gl entry has additional field lests say AppID
    if givenRec.Apply ID = ''
    then CurrGLEntry SETRANGE(givenRec.EntryNo)
    ELSE
    currGLEntry.SETRANGE(givenRec.Apply ID)
    //my global variable is AppID Code
    AppID := givenRec.Apply ID;

    I also tried to create another global variable TempEntry And Tempentry.TRANSFERFIELDS(CurrGLEntry);
    to get Apply ID form it.

    Then
    FORM.RUNMODAL(Form,CurrGlEntry);
    //

    I checked in debugger, it sets correctly a value to AppID or TempEntry. But when i try to use these values they are empty.

    Please help.. :(
  • mihail_kolevmihail_kolev Member Posts: 379
    ...aaaand, where you try to get this value?
    -Mihail- [MCTS]
  • wilk_uwilk_u Member Posts: 94
    In another function in that codeunit

    Function2()

    IF AppID <> comparedWithSth THEN...
    and here that value appears as empty
  • MBergerMBerger Member Posts: 413
    i am guessing you have declared your codeunit in the form too, and are trying to read the variable from there. You have to realise that by default, every time you declare a variable of your codeunit, it will be a seperate instance ! Either set the "single instance" property of the codeunit to "yes", or make function in the form you want to run to pass the values.
  • wilk_uwilk_u Member Posts: 94
    You may be right if i understand You correctly.
    I declared codeunit in form as global variable, and trying to execute functions from codeunit. Then i have empty values. So You say to declare single instance codeunit? I heard its not safe.. Is that right?
    Regards.
  • krikikriki Member, Moderator Posts: 9,110
    [Topic moved from 'NAV Three Tier' forum to 'NAV/Navision Classic Client' forum]
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.