Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Set a default value for a new Field in an Table Extension

Posted on by 185

Hi,

I have created a table extension for InventTable and I have added two new string fields. I want to set this field to a default value in the EcoResProductDetailsExtended form which I have extended.

Can some one please advise on how I can do this?

KR Norm

*This post is locked for comments

  • RE: Set a default value for a new Field in an Table Extension

    Hi Abbas,

    I have updated the thread accordingly.

    Thanks for your help.

    KR Norm

  • RE: Set a default value for a new Field in an Table Extension

    Hi Norman,

    Good to hear that your problem solved. I think you should mark Martin Dráb thread as a verified answer instead of yours. Its helps to find the exact answer for this thread.

    Br Abbas

  • RE: Set a default value for a new Field in an Table Extension

    Thanks Martin - that worked nicely.

    KR Norm

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: Set a default value for a new Field in an Table Extension

    Don't bother with these ugly events pre-/post-method handlers - every table comes with modeled events such as onInitializingRecord, onInitalizedRecord, onUpdating and so on. Right-click the event you need, choose Copy event handler method which puts the declaration to clipboard, paste it to a class and write your business logic there.

  • AX 2012 r3 Profile Picture
    AX 2012 r3 2,420 on at
    RE: Set a default value for a new Field in an Table Extension

    Inventtable.InitValue()

     

  • RE: Set a default value for a new Field in an Table Extension

    Hi Abbas,

    the field I have added will be set to the product category top level.

    So, if this product category changes then the InventTable record will need to reflect this change to the user.

    KR Norm

  • Suggested answer
    RE: Set a default value for a new Field in an Table Extension

    Hi Norman,

    InitValue method will work only when you are creating new record. For existing you better use runnable class to update the existing records..

    Br Abbas

  • RE: Set a default value for a new Field in an Table Extension

    Hi Abbas,

    that compiled and worked well for the creation of new released products.

    I would also like this functionality when viewing existing items.

    What method should I override?

    Thanks for your help.

    KR Norm

  • RE: Set a default value for a new Field in an Table Extension

    Sorry my mistake, Write like below,

    [ExtensionOf(tableStr(InventTable))]

    final class InventTable_Extension

    {

      [PreHandlerFor(tableStr(InventTable), tableMethodStr(InventTable, initValue))]

      public static void InventTable_Pre_initValue(XppPrePostArgs args)

      {

           InventTable inventTable = args.getThis() as InventTable;

           inventTable.ItemClass= WSDItemClass::find(this.ItemId, false).ItemClass;

           inventTable.ItemDescription = "Direct value assignment";

      }

    }

    Br Abbas

  • RE: Set a default value for a new Field in an Table Extension

    The error I get is

     'this' is not valid in a static method.

    KR Norm

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans