Skip to main content



No record found.

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

Issue with clearing table buffers in called class.

Posted on by 40
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 (
             if (queryRun.changed(tableNum(InventTable)))
                 InventTable                 inventTable             = queryRun.get(tableNum(InventTable));
                 EcoResCategory          ecoResCategory     = queryRun.get(tableNum(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 40 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 225,490 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

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans