web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Should we always call Table.initValue() method?

(1) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi sanme,

    See this link for details:

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

  • Suggested answer
    Community Member Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

    Hi sanme,

    This might help

    www.axaptapedia.com/Temporary_tables

  • Verified answer
    Maciej Obojski Profile Picture
    610 on at

    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

  • Suggested answer
    Community Member Profile Picture
    on at

    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;

  • Community Member Profile Picture
    on at

    Any other inputs before I make a conclusion? Thanks.

  • Verified answer
    Martin Dráb Profile Picture
    237,961 Most Valuable Professional on at

    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.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans