Get the ranges and values from Query ( Dynamic/AOT ) using X++ in Ax 2012

My Previous Post:Get the ranges and values from Query ( Dynamic/AOT ) using X++ in Ax 2009 

https://jkmsdax2012.wordpress.com/2015/05/05/get-the-ranges-and-values-from-query-dynamicaot-using-x-in-ax-2009/

static void Johnkrish_GetRangeValueOfQuery(Args _args)
{
Query query;
QueryRun queryRun;
QueryBuildDataSource qbd;
GeneralJournalAccountEntry vendTable;
QueryBuildRange range;
QueryFilter qf;
GeneralJournalAccountEntry generalJournalAccountEntry;
int cnt, i;
;

query = new query();
qbd = query.addDataSource(tablenum(GeneralJournalAccountEntry));
queryRun = new QueryRun(query);
queryRun.prompt();
query = queryRun.query();
cnt=query.queryFilterCount();

for (i = 1; i <=cnt ; i++)
{
qf = query.queryFilter(i);
info(strFmt(“Range Field – %1: Value – %2”, qf.field(), qf.value()));
}

while (queryRun.next())
{
generalJournalAccountEntry = queryRun.get(tablenum(GeneralJournalAccountEntry));
info(strfmt(“PostingType – %1, LederAccount – %2”,generalJournalAccountEntry.PostingType, generalJournalAccountEntry.LedgerAccount));
}
}

Output:

QueryWindow

Output

 

Advertisements

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

}