AX – D365FO – X++ – Retrieve multiple occurrences of a DataSource in a QueryBuilDer with dataSourceTable method

When you make a query it can happen that you use more than one data source for the same table.

If you use the query builder you will have to set the filters on the right data source. If you have multiple data sources for the same table the only way to select the correct one is to select the one with the right index.

To do this you can use Query.dataSourceTable (Int32, Int32) Method.
In the first parameter you have to set the table id, while in the second the index corresponding to the data source you want to use (the first, the second, etc.)

public void method()
  {
      QueryBuildDataSource        qbdsPurchLineA;
      QueryBuildDataSource        qbdsPurchLineA;

      qbdsPurchLineA = this.query().dataSourceTable(tableNum(PurchLine), 1);

      qbdsPurchLineA.addRange(fieldnum(PurchLine, PurchStatus)).value(queryvalue(PurchStatus::Backorder));

      qbdsPurchLineB = this.query().dataSourceTable(tableNum(PurchLine), 2);

      qbdsPurchLineB.addRange(fieldnum(PurchLine, PurchStatus)).value(queryvalue(PurchStatus::Backorder));
  }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s