Skip to main content

Notifications

Microsoft Dynamics AX (Archived)

Should we always call Table.initValue() method?

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

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

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,900 Most Valuable Professional on at
    RE: Should we always call Table.initValue() method?

    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.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Should we always call Table.initValue() method?

    Any other inputs before I make a conclusion? Thanks.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Should we always call Table.initValue() method?

    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;

  • Verified answer
    Maciej Obojski Profile Picture
    Maciej Obojski 610 on at
    RE: Should we always call Table.initValue() method?

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Should we always call Table.initValue() method?

    Hi sanme,

    This might help

    www.axaptapedia.com/Temporary_tables

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Should we always call Table.initValue() method?

    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.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Should we always call Table.initValue() method?

    Hi sanme,

    See this link for details:

    msdn.microsoft.com/.../aa602944.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans