Skip to main content

Notifications

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

  • Martin Dráb Profile Picture
    232,964 Most Valuable Professional on at
    RE: Relation VIEWS and DataSource in a FORM

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

  • Community Member Profile Picture
    on at
    RE: Relation VIEWS and DataSource in a FORM

    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

  • Community Member Profile Picture
    on at
    RE: Relation VIEWS and DataSource in a FORM

    Thank you for the great help.

  • Verified answer
    Martin Dráb Profile Picture
    232,964 Most Valuable Professional on at
    RE: Relation VIEWS and DataSource in a FORM

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

  • Verified answer
    nmaenpaa Profile Picture
    101,158 Moderator on at
    RE: Relation VIEWS and DataSource in a FORM

    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.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,165 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,964 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans