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

Announcements

News and Announcements icon
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,645

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

I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    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

  • AlokShrestha Profile Picture
    1,645 on at

    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". 

  • Mea_ Profile Picture
    60,286 on at

    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,645 on at

    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,286 on at

    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,645 on at

    Yup, just running it. Will post the result.

  • AlokShrestha Profile Picture
    1,645 on at

    That worked. Thank you so much.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans