Ax 2012: How to add TWO links between two datasources in X++ Query

In my Customization I need to get the From warehouse and To warehouse transaction from the Inventory Transfer Journal.

for this i need to relate  InventJournalTrans and InventTransOrigin tables with InventTransId and ToInventTransId, But here InventTransId is a direct relation, but if i use this relation then i can get only the From warehouse information. The linking is like the below

qbds1.relations(true);
qbds1.addLink(fieldnum(InventJournalTrans,InventTransId),fieldnum(InventTransOrigin,InventTransId));

but i can’t make two relations like

qbds1.relations(true);
qbds1.addLink(fieldnum(InventJournalTrans,InventTransId),fieldnum(InventTransOrigin,InventTransId));qbds1.addLink(fieldnum(InventJournalTrans,ToInventTransId),fieldnum(InventTransOrigin,InventTransId));

so i code like Range setting in X++ query.

CODE: JOB

static void GetFromAndToWarehouse(Args _args)
{
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
InventTransOrigin inventTransOrigin;
InventTrans inventTrans;
InventDim inventDim;

Query query;
QueryBuildDataSource qbds,qbds1,qbds2;
QueryBuildRange qbr,qbr1;
QueryRun queryRun;

query=new Query();

qbds=query.addDataSource(tableNum(InventJournalTrans));
qbr = qbds.addRange(fieldNum(InventJournalTrans, JournalId));
qbr.value(queryValue(“00081”));

qbds1 = qbds.addDataSource(tableNum(InventTransOrigin));
qbr1 = qbds1.addRange(fieldNum(InventTransOrigin, InventTransId));
qbr1.value(strFmt(“((%1.INVENTTRANSID == %2.INVENTTRANSID) || (%1.INVENTTRANSID == %2.TOINVENTTRANSID))”,qbds1.name(), qbds.name()));

qbds2=qbds1.addDataSource(tableNum(InventTrans));
qbds2.joinMode(JoinMode::InnerJoin);
qbds2.relations(true);

queryRun = new QueryRun(query);

while (queryRun.next())
{
inventTrans = queryRun.get(tableNum(InventTrans));
inventDim = InventDim::find(inventTrans.InventDimId);
info(strFmt(“%1”,inventDim.InventLocationId));
}

}

 

Advertisements

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 )

Google+ photo

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

Connecting to %s