Active Record

Hi. I have a problem. Look in the code:

public void executeQuery()
{
Query purchLineQuery, purchTableQuery;

QueryRun purchLineQR1;
;

purchLineQuery = PurchLine_ds.query();
purchLineQuery.dataSourceNo(1).addRange(fieldnum(purchLine, ItemId)).value(“00022”); //<— IN HERE

purchTableQuery = PurchTable_ds.query();

purchLineQR1 = new QueryRun(purchLineQuery);
//zczytać wyniki
while(purchLineQR1.next())
{

purchLine = purchLineQR1.get(tableNum(PurchLine));
//info(purchTable.PurchId);
//info(purchLine.PurchId);
//Zbudować zakres do Purchtable.
purchTableQuery.dataSourceNo(1).addRange(fieldnum(purchTable, PurchId)).value(PurchLine.PurchId);

}

super();
}

I have a form with two grids. In value(####) i want to put a active record from a first grid.there are no relatnio beetwen the grids. First grid data source is InventTable, the second is PurchTable. and the relation is InvenTable.ItemId = PurchLine.ItemId and purchLine.PurchId= PurchTable.PurchId

I already told you that you shouldn’t write any code like this. All you need to do is to correctly link the data sources; AX will handle the rest. If you don’t trust the answers you get, you’ll have to follow the wrong way alone.

Dear Martin

I know that I must link the data sources and I done it, but know my Boss tell me that I must write all in x++.

OK I give up.

Thank’s all for help.

Do the right thing and educate your boss. You would just waste your time with the code above.

Create three data sources:

  • InventTable
  • PurchTable (JoinSource: InventTable, LinkType: Delayed),
  • PurchLine (JoinSource: PurchTable, LinkType: ExistJoin)

and add the following piece of code to init() method of PurchLine data source (below super()):

this.queryBuildDataSource().addDynalink(
            fieldNum(PurchLine, ItemId),
            inventTable,
            fieldNum(InventTable, ItemId));

One grid will have InventTable as its data source, the other will use PurchTable.

When you select an item, related orders will be shown in the other grid.