Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Issue with clearing ta...
Finance forum
Unanswered

Issue with clearing table buffers in called class.

Posted on by 35
Hello,
 
I have a logic where I am looping though a queryRun object in class A and inside the loop I am calling class B and passing the table records of the query as parameters:
Logic of class A:
public void run()
{
         ClassB classB = ClassB::construct();
         while (queryRun.next())
         {
             if (queryRun.changed(tableNum(InventTable)))
             {
                 InventTable                 inventTable             = queryRun.get(tableNum(InventTable));
                 EcoResCategory          ecoResCategory     = queryRun.get(tableNum(EcoResCategory));
 
                 classB.createDefails(inventTable,
                         ecoResCategory);
            }
        }
}
Logic of class B:
public void createDetails(InventTable _inventTable, EcoResCategory _ecoResCategory)
{ //line 7
    inventTable.clear(); //line8
    ecoResCategory.clear(); //line9
  
    inventTable                    = _inventTable;
    ecoResCategory             = _ecoResCategory; 
    //processing logic
}
 
In class B, I have global variables InventTable and EcoResCategory which will be used. I have added a logic in class B's createDetails to clear those 2 variables. However, I have a very weird behaviour where upon clearing those 2 variables of class B, the variables passed as parameters (_inventTable and _ecoResCategory) are also being cleared. It works fine when the logic of createDetails is executed for the first loop, but then for the following loops both the global variables and parameter variables become null after the line 9 execution. When debugging, _inventTable and _ecoResCategory have their respective records at line 7 but then they become null after line 9.
I have commented line 8 and 9 and it works fine now but I could not understand why they were causing this issue.
Has anyone had this issue before?
 
 
  • CU15051611-0 Profile Picture
    CU15051611-0 35 on at
    Issue with clearing table buffers in called class.
    Hello Martin,
    The code logic was slightly different before and changed afterwards.
    I had a condition previously to create a new product if a certain condition was true, else take the records passed as parameters to create custom details.
    I had forgotten to remove the clear call of the variables when the creation of new product was no longer needed.
    However, I did not know that the fact that the parameters variable and global variable pointing to the same value could pose an issue when clearing the buffers.
  • Martin Dráb Profile Picture
    Martin Dráb 224,741 Super User on at
    Issue with clearing table buffers in called class.
    I see what your code does but I don't know what behavior you intended to develop.
     
    When you assign _inventTable to inventTable, for example, both variables point to a single object.
     
    Why do you call clear() at all if you immediately overwrite values of inventTable and ecoResCategory anyway? Shouldn't you simply stop calling clear()?

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,663 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,741 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans