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)

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

    Hi,

    Please use InitValue method in InventTable and assign your default values which will reflect in EcoResProductDetailsExtended.

    Br Abbas

  • Norman Elliott - Malta Profile Picture
    185 on at

    Hi Abbas,

    can you please let me know the syntax to set the WSD field in this method

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

       public static void InventTable_Pre_initValue(XppPrePostArgs args)

       {

           // WSD  ? how to set this field

           ;

       }

    Thanks

    KR Norm

  • Abbas Ithayathullah Profile Picture
    175 on at

    Hi Norman,

    For example,  i have two fields created in Inventable called ItemClass and ItemDescription the code is look like below,

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

      public static void InventTable_Pre_initValue(XppPrePostArgs args)

      {

         this.ItemClass = WSDItemClass::find(this.ItemId, false).ItemClass;  // this is ex of takeing value from different table based on the itemid... (This line is for example i created myself... use your own table.

         this.ItemDescription = "Direct value assignment";

          ;

      }

    Br Abbas

  • Norman Elliott - Malta Profile Picture
    185 on at

    Hi Abbas,

    'this.' does not resolve.

    Can you please advise?

    KR Norm

  • Norman Elliott - Malta Profile Picture
    185 on at

    Hi Abbas,

    I created a class called  InventTable_Extension

    Then added this code -->

    [ExtensionOf(tableStr(InventTable))]

    final class InventTable_Extension

    {

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

       public static void InventTable_Pre_initValue(XppPrePostArgs args)

       {

           this.

       }    

    }

    'This' does not resolve!

    Can you please advise?

    Thanks

    KR Norm

  • Norman Elliott - Malta Profile Picture
    185 on at

    The error I get is

     'this' is not valid in a static method.

    KR Norm

  • Abbas Ithayathullah Profile Picture
    175 on at

    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

    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

  • Suggested answer
    Abbas Ithayathullah Profile Picture
    175 on at

    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

    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

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
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans