Hi All,
May I know should we always call initValue() method for eg: LedgerJournalTable, LedgerJournalTrans, CustTable....
Any documentation / best practice have mention we should call this method during create new record via X++?
Thank you.
*This post is locked for comments
In most cases, it doesn't matter whether you call it or not as long as it isn't overridden. But it still makes sense to me to call it, exactly because somebody may override it later and will expect it to be applied consistently everywhere.
Nevertheless there is one special thing to take into account: record templates. If you have a default template, it will be applied by initValue(), if you have templates to choose from, a dialog will be displayed. This may or may not be the expected behaviour.
Any other inputs before I make a conclusion? Thanks.
Hi ,
I agree with you, but if you read the question carefully, it is asking if its necessary to explicitly call .initvalue() when inserting data using X++ eg
ttsbegin;
MyTable.initvalue();
MyTable.field1 ="Value1";
MyTable.field2 ="Value2";
MyTable.insert();
ttscommit;
Hi,
first of all - Robert, I am afraid you are wrong with your comment regarding 'insert' method. What does actually happen is that when a user creates a new record via a Form, then AX automatically calls the 'initValue' method from underlying table. However it definitely does not happen during 'insert.
Sanme - yes, it is usually a good practice to call 'initValue' - it does get called on all of the forms, so your personalised code should work the same. However this rule is not explicitly listed as Microsoft Best Practice.
The only reason I can think of, is that a Best Practice is a rule that should always be followed - but there might be times when you are not interested in standard AX code in the 'initValue', and you'd prefer to handle this in your own way, according to business logic.
Thanks,
Maciej
The initvalue() is usually executed automatically on insert and it loads the default values, so no need to explicitly call it. You can also override it and initialize fields to new default values you want.
André Arnaud de Cal...
292,074
Super User 2025 Season 1
Martin Dráb
230,900
Most Valuable Professional
nmaenpaa
101,156