Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

How to add a data source to an existing query in ax 7

Posted on by 230

3276.Capture.JPGHi ,

I have a view which has a metadata as a query (Screenshot below)

I want to add a data source to the existing query DirQuery in Ax 7. How do i achieve it. I have tried to use the OnInitialized event handler of the view, in a new class with the following code below but its not working.(St is the datasource , i am trying to add on the query DirQuery)

class CMCDirPartyViewQuery
{

[FormDataSourceEventHandler(formDataSourceStr(DirPartyTableRoles, DirPartyView), FormDataSourceEventType::Initialized)]
public static void DirPartyView_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
{
Query query;
QueryBuildDataSource qbds;
//query = sender.query();
query = new Query(queryStr(DirQuery));
qbds = query.dataSourceTable(tableNum(DirPartyView)).addDataSource('St');
qbds.clearLinks();
qbds.relations(true);
qbds.joinMode(JoinMode::InnerJoin);
qbds.fetchMode(QueryFetchMode::One2One);
qbds.addLink(fieldnum(St, Person), fieldnum(DirPartyView, Party));
qbds.addRange(fieldNum(St, Person));

}

}

 

Regards,

Sourav

1616.Capture.JPG

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to add a data source to an existing query in ax 7

    Hi Saurav ,

    Have You find any solution for this I am also having the same problem.

    My requirement is to add new DataSource via an extension.

    Thanks in advance.

  • Verified answer
    Basheer17 Profile Picture
    Basheer17 2,720 on at
    RE: How to add a data source to an existing query in ax 7

    You must have created an extension model for creating Query extension, add the reference of the other model where your required Table is residing, this will allow you to add datasource to your query.

  • Saurav Profile Picture
    Saurav 230 on at
    RE: How to add a data source to an existing query in ax 7

    Hi,

    This was a good idea which you mentioned. but the problem we are facing is the query is in application suite. The datasource we are trying to add is in lower package which application suite cannot extend. In 2012 this was feasible but in ax 7 we have this limitation..

    Regards,

    Sourav

  • Saurav Profile Picture
    Saurav 230 on at
    RE: How to add a data source to an existing query in ax 7

    31704.Capture.JPGAlright, What we are trying here is as below:

    We have a view DirPartyView in ax  which has the metadata as DirQuery( query). The structure is as below for the view. Now i want to add two more datasources(These are customized tables) to the existing query . Both the View and the query are in Application suite. However we have created a new package where we have all our customized object(Including the two tables i want to add as datasource). How can we achieve this. So basically i want to add a new datasource to an existing query in ax 7

  • Basheer17 Profile Picture
    Basheer17 2,720 on at
    RE: How to add a data source to an existing query in ax 7

    If your new data source that you are about to add has any relation with the existing datasources, then you can add it to the datasource node of existing datasource.

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to add a data source to an existing query in ax 7

    You can add only embedded datasource via extension. Could you please tell us what do you actually want to achieve ? Maybe there is another way to do this.

  • Saurav Profile Picture
    Saurav 230 on at
    RE: How to add a data source to an existing query in ax 7

    0243.Capture.JPGHi Ievgen,

    I have tried doing that too but unfortunately a query extension does not allow you to add a datasource(Screenshot below):

  • Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to add a data source to an existing query in ax 7

    You have new extension model, let's call it "Application Suite Extensions". You extending your query to "Application Suite Extensions" model. Now you can add reference to that " lower model" and use that table, why not ?

  • Saurav Profile Picture
    Saurav 230 on at
    RE: How to add a data source to an existing query in ax 7

    Yah .. I am aware about that.. Here lies the problem... The query is in Application Suite but the table i am trying add to the datasource belong to another  lower model which cannot be extended to the application suite.. Sorry for missing that info in my question.. This was allowed in ax 2012 but unfortunately we are unable to use any object which are in lower model in application suite .. So i was trying to dynamically add the datasource by using the event handler for the view which belongs to application suite in a new class created in my model.. Any suggestion on this

  • Suggested answer
    Mea_ Profile Picture
    Mea_ 60,278 on at
    RE: How to add a data source to an existing query in ax 7

    Hi Saurav,

    Did you try to extend a query ? You can find DirQuery in AOT -> right click -> Create extension.Then you can add new datasource to a query via extension.

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