Search code examples
axaptamicrosoft-dynamicsdynamics-ax-2012x++dynamics-ax-2012-r3

Add grid columns dynamically


I created a form with a single data source: InventJournalTable.

I also added a grid on it and two field from the data source : JournalType and JournalId

The ActionPane has a button and in its clicked event handler I am trying to do the following:

1.  add a new data source and join it with the current one on JournalId
2.  add to fields from the newly added data source to the current Grid. 

This is what I have until now ... just for testing.. I have tried to access data source and add a range. It works nice, maybe the join is working too, but how can I add those two fields?

void clicked()
{
    Query query;
    QueryBuildDataSource qbdsInventJournalTable;
    QueryBuildDataSource qbdsvwInventJournals;

    super();

    query = InventJournalTable_ds.query();
    qbdsInventJournalTable = query.dataSourceTable(tableNum(InventJournalTable));

    qbdsInventJournalTable.addRange(fieldNum(InventJournalTable, JournalType)).value(queryValue(InventJournalType::LossProfit));

    qbdsvwInventJournals = qbdsInventJournalTable.addDataSource(tableNum(vwInventAdjJrnlCostAmount));
    qbdsvwInventJournals.addLink(fieldNum(InventJournalTable, JournalId), fieldNum(vwInventAdjJrnlCostAmount, JournalId));
    qbdsvwInventJournals.joinMode(JoinMode::OuterJoin);

    //gridOverview.addDataField(

    InventJournalTable_ds.executeQuery();
}

One more thing, I plan to add another button named "Remove details" which will remove the second data source and the grid should return to its initial state.

Am I on the right track at least? Can I get some hints about this?


Solution

  • Instead of dynamically adding the datasource/fields/etc have you considered just adding them on the form, but disabling the joined datasource until you need it? Seems to me like a simpler/cleaner solution.

    See here: http://olondono.blogspot.com/2008/06/how-to-enable-or-disable-joined.html