Setting and accessing global variable

havhav Member Posts: 299
Hi All,
I am facing problem with setting and accessing a global boolean var.
I have added a global boolean var. CalledFromSynchronisation to SalesLine table. This table contains a fn. to set the value of this var.as shown below:
SetCalledFromSynchronisation(Flag : Boolean)
{
CalledFromSynchronisation := Flag;
}

I have a codeunit which modifies the SalesHeader record as below:
UpdateSalesHeader(VAR SalesHeader : Record Sales Header)
{
....................
SalesHeader.VALIDATE("Sell-to Customer No.");
..........

}
The above validation calls the below fn. of SalesHeader table
RecreateSalesLines()
{
...............
//Purpose : Set synchronisation flag to restrict deletion of Items
SalesLine.SetCalledFromSynchronisation(TRUE);


SalesLine.DELETEALL(TRUE);
....................

}
Note: Modified code is in red bits

When the OnDelete() of SalesLine table is called from the above fn. and i debug the OnDelete(), what i found is that the global boolean var. CalledFromSynchronisation is not set to TRUE in spite of settting it explicitly from RecreateSalesLines(). The OnDelete() of SalesLine table is as follows:
OnDelete()
{
.......
IF NOT CalledFromSynchronisation THEN
//do someting

.......
}

While debugging when i place curson at CalledFromSynchronisation var. above it shows me "No"
I am unable to trap this.

Pls help.

Regards,
Regards,
Hemant
MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)

Comments

  • ara3nara3n Member Posts: 9,256
    try to loop through the saleslines and do delete(true) instead of deleteall(true)
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • havhav Member Posts: 299
    The code in green bits is the Navision code. The code which i have modified is shown in red bits
    Regards,
    Hemant
    MCTS (MB7-841 : NAV 2009 C/SIDE Solution Development)
  • kinekine Member Posts: 12,562
    Some triggers are running in their own "instances". It means when you call DELETEALL(true), you can "look behind the code" and see something like:
      if FIND('-') then
      repeat
         InternalVar := Rec;
         InternalVar.DELETE(True);
      until NEXT=0;
    

    It means that there is no flag set in the InternalVar instance of the table. As ara3n wrote, try to use the loop instead DELETEALL.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.