I got one tasks of report development in which I have to show the Financal Dimension and its Dimension Value in a lookup on report parameter.
The form for Financial Dimension is.
As you can see in the above image there is a dimension value button when you click on it a new form will open containing all of the dimensions against that selected Financial Dimension.
So the question is how can we get the Dimension Values based Financial Dimension by using query.
Below is the code for you:
class RunnableClass1
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
DimensionAttribute dimAttr;
DimensionAttributeViewContract dimAttrViewContract;
Query q;
QueryRun qR;
QueryBuildDataSource qbds;
Common common;
dimAttr = DimensionAttribute::findByName("Department");
dimAttrViewContract = DimensionAttribute::getViewContract(dimAttr.RecId);
q = new Query();
changecompany (dimAttr.company())
{
qbds = q.addDataSource(dimAttrViewContract.parmViewId());
qbds.addSortField(dimAttrViewContract.parmValueFieldId(),SortOrder::Ascending);
// Apply ranges on language ID fields.
DimensionAttribute::addTranslViewRangesToBackingEntityQuery(dimAttr.RecId, qbds);
if (DimensionCache::instance().dimensionAttributeHasCategorization(dimAttr.RecId))
{
if (dimAttr.Type == DimensionAttributeType::MainAccount)
{
qbds.addRange(dimAttrViewContract.parmCategoryFieldId()).value(queryValue(LedgerChartOfAccounts::current()));
}
else if (dimAttr.Type == DimensionAttributeType::CustomList)
{
qbds = qbds.addDataSource(tablenum(DimensionAttributeDirCategory), 'DimAttDirCat');
qbds.relations(true);
qbds.joinMode(JoinMode::InnerJoin);
qbds.fetchMode(QueryFetchMode::One2One);
qbds.addLink(dimAttrViewContract.parmCategoryFieldId(), fieldnum(DimensionAttributeDirCategory, DirCategory));
qbds.addRange(fieldnum(DimensionAttributeDirCategory, DimensionAttribute)).value(strfmt('%1', dimAttr.RecId));
}
}
}
qR = new QueryRun(q);
while(qR.next())
{
common = qR.get(dimAttrViewContract.parmViewId());
info(strFmt("%1 %2",common.getFieldValue(dimAttrViewContract.parmValueFieldName()), common.getFieldValue(dimAttrViewContract.parmNameFieldName())));
}
}
}
For more Details Below is the link:
https://community.dynamics.com/ax/b/hellodax/archive/2015/07/07/get-all-financial-dimension-value-and-description-from-dimensionattribute
Thanks,
Zahid
To do this the one I have to grab all the Dimension Values against the Financial Dimension to show in a lookup.
Below is the navigation for Financial Dimension Form in D365:
General Ledger -> Chart of Accounts -> Dimension -> Financial Dimensions.
The form for Financial Dimension is.
As you can see in the above image there is a dimension value button when you click on it a new form will open containing all of the dimensions against that selected Financial Dimension.
So the question is how can we get the Dimension Values based Financial Dimension by using query.
Below is the code for you:
class RunnableClass1
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
DimensionAttribute dimAttr;
DimensionAttributeViewContract dimAttrViewContract;
Query q;
QueryRun qR;
QueryBuildDataSource qbds;
Common common;
dimAttr = DimensionAttribute::findByName("Department");
dimAttrViewContract = DimensionAttribute::getViewContract(dimAttr.RecId);
q = new Query();
changecompany (dimAttr.company())
{
qbds = q.addDataSource(dimAttrViewContract.parmViewId());
qbds.addSortField(dimAttrViewContract.parmValueFieldId(),SortOrder::Ascending);
// Apply ranges on language ID fields.
DimensionAttribute::addTranslViewRangesToBackingEntityQuery(dimAttr.RecId, qbds);
if (DimensionCache::instance().dimensionAttributeHasCategorization(dimAttr.RecId))
{
if (dimAttr.Type == DimensionAttributeType::MainAccount)
{
qbds.addRange(dimAttrViewContract.parmCategoryFieldId()).value(queryValue(LedgerChartOfAccounts::current()));
}
else if (dimAttr.Type == DimensionAttributeType::CustomList)
{
qbds = qbds.addDataSource(tablenum(DimensionAttributeDirCategory), 'DimAttDirCat');
qbds.relations(true);
qbds.joinMode(JoinMode::InnerJoin);
qbds.fetchMode(QueryFetchMode::One2One);
qbds.addLink(dimAttrViewContract.parmCategoryFieldId(), fieldnum(DimensionAttributeDirCategory, DirCategory));
qbds.addRange(fieldnum(DimensionAttributeDirCategory, DimensionAttribute)).value(strfmt('%1', dimAttr.RecId));
}
}
}
qR = new QueryRun(q);
while(qR.next())
{
common = qR.get(dimAttrViewContract.parmViewId());
info(strFmt("%1 %2",common.getFieldValue(dimAttrViewContract.parmValueFieldName()), common.getFieldValue(dimAttrViewContract.parmNameFieldName())));
}
}
}
For more Details Below is the link:
https://community.dynamics.com/ax/b/hellodax/archive/2015/07/07/get-all-financial-dimension-value-and-description-from-dimensionattribute
Thanks,
Zahid