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

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

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

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Norman Elliott - Malta Profile Picture
    185 on at
    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

  • Abbas Ithayathullah Profile Picture
    175 on at
    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

  • Norman Elliott - Malta Profile Picture
    185 on at
    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
    236,233 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
    2,426 on at
    RE: Set a default value for a new Field in an Table Extension

    Inventtable.InitValue()

     

  • Norman Elliott - Malta Profile Picture
    185 on at
    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
    Abbas Ithayathullah Profile Picture
    175 on at
    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

  • Norman Elliott - Malta Profile Picture
    185 on at
    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

  • Abbas Ithayathullah Profile Picture
    175 on at
    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

  • Norman Elliott - Malta Profile Picture
    185 on at
    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

Responsible AI policies

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

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans