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)

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

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

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

    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.

  • Saurav Profile Picture
    230 on at

    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

  • Mea_ Profile Picture
    60,284 on at

    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
    230 on at

    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
    60,284 on at

    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.

  • Basheer17 Profile Picture
    2,720 on at

    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.

  • Saurav Profile Picture
    230 on at

    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

  • Saurav Profile Picture
    230 on at

    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

  • Verified answer
    Basheer17 Profile Picture
    2,720 on at

    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.

  • Community Member Profile Picture
    on at

    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.

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans