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));
}

}

 

How to Get Financial Dimensions for a particular Customer using X++ code in Ax 2012

TWO Ways:

Way 1:

static void GetFinancialDimensionValue(Args _args)
{
CustTable custTable ;
DimensionAttributeValueSet DimensionAttributeValueSet;
DimensionAttributeValueSetItem DimensionAttributeValueSetItem;
DimensionAttributeValue DimensionAttributeValue;
DimensionAttribute DimensionAttribute;

while select * from custTable
where custTable .AccountNum == “CU0000001″
join RecId from DimensionAttributeValueSet
where DimensionAttributeValueSet.RecId == custTable .DefaultDimension
join RecId, DisplayValue from DimensionAttributeValueSetItem
where DimensionAttributeValueSetItem.DimensionAttributeValueSet == DimensionAttributeValueSet.RecId
join RecId from DimensionAttributeValue
where DimensionAttributeValue.RecId == DimensionAttributeValueSetItem.DimensionAttributeValue
join RecId, Name from DimensionAttribute
where DimensionAttribute.RecId == DimensionAttributeValue.DimensionAttribute
{
info(DimensionAttribute.Name+”—-“+ DimensionAttributeValueSetItem.DisplayValue);
}
}

Way 2:

static void GetFinancialDimensionValue1(Args _args)
{
CustTable custTable = CustTable::find(“CU0000001”);
DimensionAttributeValueSetStorage dimStorage;
Counter i;

dimStorage = DimensionAttributeValueSetStorage::find(custTable.DefaultDimension);

for (i=1 ; i<= dimStorage.elements() ; i++)
{

//if you want particular Dimension then put if condition like this
//if(strFmt(“%1″,DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name)==”Specialty”)
// {
info(strFmt(“%1 = %2”, DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name,
dimStorage.getDisplayValueByIndex(i)));
//}
}

}

 

Ax 2012 Arrays

An array is a collection of variables that are all of the same type. The elements of an array are accessed with simple integer indexes.

There are three kinds of arrays:

  • Dynamic
  • Fixed-length
  • Partly on disk

X++ only supports one-dimensional arrays. It is possible, however, to mimic the behavior of multiple array indices.

Example JOB:

static void ArrayTypes(Args _args)
{
Name DynamicArray[];
Name FixedArray[4];
//Name PartllyOnDiskArray[,8]; // if you use like this then it is Dynamic array of Name only 8 in memory
Name PartllyOnDiskArray[16,8];// if you use like this then it is Fixed length array of Name wit 16 elements and 8 in memory

int i,j;
 CustTable custTable;
 ;

while select AccountNum from custTable
where custTable.CustGroup==”30″
{
i++;
DynamicArray[i] = custTable.AccountNum;

if(i<=4)
FixedArray[i] = custTable.AccountNum;

PartllyOnDiskArray[i] = custTable.AccountNum;

}
setPrefix(“Array Types”);
setPrefix(“FixedArray”);
for (j=1;j<=dimOf(FixedArray);j++)
{
info(strFmt(“Fixed Array – %1”,FixedArray[j]));
}
setPrefix(“Dynamic Array”);
for (j=1;j<=dimOf(DynamicArray);j++)
{
info(strFmt(“Dynamic Array – %1”,DynamicArray[j]));
}
setPrefix(“PartlyOnDisk Array Memory value”);
for (j=1;j<=dimOf(PartllyOnDiskArray);j++)
{
info(strFmt(“PartlyOnDisk Array – %1”,PartllyOnDiskArray[j]));
}
setPrefix(“PartlyOnDisk Array fully printed (Disk + Memory)”);
for (j=1;j<=16;j++)
{
info(strFmt(“PartlyOnDisk Array – %1”,PartllyOnDiskArray[j]));
}

}

How can we validate our Customised/Standard( not in existing validation) field during Journal(Count & PL) validation and posting in Ax

Requirement:

When the journal is validated or posted from the post button on inventory journal or lines button on journal lines, inventory form, ensure that all the lines have adjustment code filled-in. if not, don’t post the journal and inform the user

Solution: apply the business logic in these class methods

## For Counting journal:

\Classes\InventMov_Jour_Loss_SumUp\journalCheckTrans()

## For Profit Loss journal:

*First override the method — journalCheckTrans

\Classes\InventMov_Jour_LossProfit\journalCheckTrans()

## In General

\Classes\JournalCheckPost\checkJournal()