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 :
Finance | Project Operations, Human Resources, ...
Answered

Relation VIEWS and DataSource in a FORM

(0) ShareShare
ReportReport
Posted on by

Hello everybody,

I've been trying for weeks to adding my view in AOT (ANW_GRUvwInventSum) with the SalesLine table. The challenge here is, that I had to have included the VIEW as a DataSource in the form. I've included the code so maybe you can understand, what I'm talking about. I am currently getting the error message that the DataSource object cannot be initialized. Does anyone have a solution for this? Many thanks in advance

public void init()
{
    QueryBuildDataSource oQBDS1, oQBDS2;
    Query                oQuery = new Query();
    ;

    oQBDS1 = oQuery.dataSourceName("dsANW_GRUvwInventSum");
    oQBDS2 = oQBDS1.addDataSource(tableNum(ANW_GRUvwInventSum));
    oQBDS2.joinMode(JoinMode::InnerJoin);
    oQBDS2.relations(false);
    oQBDS2.addLink(fieldNum(SalesLine, ItemId), fieldNum(ANW_GRUvwInventSum, ItemId));

    super();
}

question_5F00_001.png

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    First of all, could you just specify Join data source and Join mode in the properties of this new data source? This way you would not need to develop anything.

    If that doesn't work, and you need to define the link in code, then I think your code needs some enhancement. You should join this new data source to SalesLine data source. So one of your QueryBuildDataSource instances should point to SalesLine data source, and one of them should point to your new data source. Then you can link them.

    Additionally, if you might need to put your code after the super() call of the init method of the data source.

  • Verified answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Even if your code worked, it wouldn't have any effect. I think you want to modify the query used by the form, but that's not what you're doing. You create a completely new query, which isn't used anywhere and it'll cease to exist at the end of init() method. You also try to find dsANW_GRUvwInventSum data source in your empty query, which must fail.

    What you need to do is taking the actual form query. You can throw away addDataSource(), because you've already added the data source to the form. You also don't need setting InnerJoin in code - you can do it in data source properties. And relations(false) doesn't seem to be useful either - I think you want to add a link exactly because you can't use relations.

    Therefore all you need is something like this:

    public void init()
    {
    	super(); // Let the system initialize the data source before you try to change it
    
    	this.queryBuildDataSource().addLink(fieldNum(SalesLine, ItemId), fieldNum(ANW_GRUvwInventSum, ItemId));
    }

    By the way, why did you attach tags "Connector for CRM", "Install and Upgrade" and "Reporting and BI"?

  • Community Member Profile Picture
    on at

    Thank you for the great help.

  • Community Member Profile Picture
    on at

    Thank you for the quick help. It doesn't look as complicated as my code. I'll try it out. I'm getting one more: syntax error

    .at the moment,

    To your question:

    By the way, why did you attach tags "Connector for CRM", "Install and Upgrade" and "Reporting and BI"?

    That was my first post and after I posted my question, I saw that the TAGS belong to my question. : D

    Yes, that's not correct.

    Thank You

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    Don't worry about tags, I'll fix them.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 584 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 499 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans