Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Accessing tables in one model from another model using X++

(0) ShareShare
ReportReport
Posted on by 1,643

Hi,

     I am trying to customize DimensionLookup form which is in Dimensions model by adding some custom code in init method of the form. What I am trying to do is add a range in the query by adding two new datasources referencing DimensionAttributeValue and DimensionAttrValueLedgerOverride table. I was able to successfully add DimensionAttributeValue table as the datasource in the QueryBuildDataSource and specify the range in it as the table is in the Dimensions model itself. But, when I try to add DimensionAttrValueLedgerOverride table as a source, it won't recognize the table as it is in Ledger model rather than Dimension model. How do we approach this situation? 

Here is the one that works as DimensionAttributeValue is in Dimensions model as well. 

  qbds = queryBuildDataSource.addDataSource(tableNum(DimensionAttributeValue));

What does not work is following code as DimensionAttrValueLedgerOverride is in Ledger model

  qbds = queryBuildDataSource.addDataSource(tableNum(DimensionAttrValueLedgerOverride));

Thanks.

*This post is locked for comments

  • AlokShrestha Profile Picture
    1,643 on at
    RE: Accessing tables in one model from another model using X++

    That worked. Thank you so much.

  • AlokShrestha Profile Picture
    1,643 on at
    RE: Accessing tables in one model from another model using X++

    Yup, just running it. Will post the result.

  • Mea_ Profile Picture
    60,278 on at
    RE: Accessing tables in one model from another model using X++

    There is one ultimate solution for all build issues -> Build all models. Usually it is overkill, but defensively will solve any compile issues :)

  • AlokShrestha Profile Picture
    1,643 on at
    RE: Accessing tables in one model from another model using X++

    Yes, I instantiated the event handler result and still it's returning null. I am suspecting if the initDelegateHandler method ever got called. Also, while debugging it never goes inside initDelegateHandler after doing step into.

  • Mea_ Profile Picture
    60,278 on at
    RE: Accessing tables in one model from another model using X++

    Yep, Before calling delegate you need to instantiate event handler result:

    EventHandlerResult result = new EventHandlerResult();
    this.initDelegate(qbds, dimAttr, dimAttrViewContract, result);

    str res = result.result();
    info(res);

    Also did you try to debug to check if initDelegateHandler was ever called? Because if code was not build properly AX could use old version of code without this method.

  • AlokShrestha Profile Picture
    1,643 on at
    RE: Accessing tables in one model from another model using X++

    Hi Ievgen,

                  Thanks for your reply. I am trying to implement delegate as you mentioned. Here is the piece of code:

    In DimensionLookup form's init method I added delegate declaration as follow:

    delegate void initDelegate(QueryBuildDataSource _qbds, DimensionAttribute _dimAttr,DimensionAttributeViewContract  _dimAttrViewContract, EventHandlerResult _ret)

       {

       }

    And called it as follow in init method:

     this.initDelegate(qbds,dimAttr,dimAttrViewContract,result);

    I created the definition for the delegate as follow. For now, I just want to return string "test" for testing purpose.

    class ADA_DimensionAttrValueLedgerOverrideHelper
    {
          [SubscribesTo(formstr(DimensionLookup), delegatestr(DimensionLookup, initDelegate))]
         public static void initDelegateHandler(QueryBuildDataSource _qbds, DimensionAttribute dimAttr, DimensionAttributeViewContract           dimAttrViewContract ,EventHandlerResult result)   

      {

        result.result("test");
       }

    }

    The issue I am having is delegate method is always returning null. I was assuming, an instance of EventHandlerResult (i.e. result) should not be null and should carry "test". 

  • Verified answer
    Mea_ Profile Picture
    60,278 on at
    RE: Accessing tables in one model from another model using X++

    Hi Alok Shrestha,

    You can create delegate in your init method. Than subscribe to this delegate in Ledger model and add your data source there.

    Please read this wiki article to get more details ax.help.dynamics.com/.../delegates-for-migration

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans