AX 2012 - InventTable Set Field

I’m looking to default a field on the InventTable upon creation.

I’ve added a section in the InventTable.insert() method like the following:

//

this.initCompanyFields();

//

This method uses some logic and then sets this.field= a value.

It is not getting populated. I’ve debugged and the value is set on that field in the debug session, however it is not written to the database.

S

Hi silvano,

even though u are able to see the value of that field in debug session

i think value is getting overided after the debug session that u have observed…

in order to work on this just observe the whole insert method code…

and keep info message at the end …

so that u might observer where the value is getting changed…

Chaitanya,

Great point you raise. I ended up opening SQL mgmt studio along side my debug session. I put a break point before my method is called (in my original post) and then ran a select on a new company database and voila, this first product i was releasing was already in the table even though the insert method had not yet completed.

So, I added the following (where “this” refers to InventTable buffer):

this.MyCustomField = value_I_Want;
this.doUpdate();

This seemed to force the field to set, and immediately after the doUpdate call, it saved to the database and was present in the UI after the insert method was complete.

You have something wrong in your original code - it would be better (for readability and performance) to fix it rather then sending another request do database.

You wrote “… was already in the table even though the insert method had not yet completed”. But that’s not how insert() works - the record is created when super() is called, not when the method completes. Did you write your code before super() in insert()?

Martin,

Good catch, it is indeed after the super(); call:

try

{

ttsbegin;

this.insertInventItemOrderSetup();

//

BOMLevelCalc::checkLevelRecalcInventTable(this);

//

super();

//

this.initPdsVendorCheckFromInventModelGroup();

//

//

this.initCompanyFields();

//

ttscommit;

}

catch (Exception::Deadlock)

{

retry;

}