AX7 · Dimensions

Dimension lookup in AX7

Recently I got a chance to work on AX7 development and design an SSRS report to provide specific default dimension as a parameter and display its details in report. Microsoft made few changes in dimension framework and depreciated some objects with new classes.

dimensionparameter

First, we have to add/modify development model to “Dimensions”package reference. Next create contract class and create parm methods for the dimensions to display as a parameter in report, in my case i have to show two dimensions (Cost center and Company).

Global variables:

DimensionValue     costCenterDimensionValue;
DimensionValue     companyDimensionValue;

parm methods:

[
    DataMemberAttribute('CostCenterDimensionValue'),
    SysOperationLabelAttribute('Cost center'),
    SysOperationDisplayOrderAttribute('1')
]
public DimensionValue parmCostCenterDimensionValue(DimensionValue _costCenterDimensionValue = costCenterDimensionValue)
{
    costCenterDimensionValue = _costCenterDimensionValue;
    return costCenterDimensionValue;
}

[
    DataMemberAttribute('CompanyDimensionValue'),
    SysOperationLabelAttribute('Company'),
    SysOperationDisplayOrderAttribute('2')
]
public DimensionValue parmCompanyDimensionValue(DimensionValue _companyDimensionValue = companyDimensionValue)
{
    companyDimensionValue = _companyDimensionValue;
    return companyDimensionValue;
}

Next Create UIBuilder class and add following code:

DialogField     dialogFieldCostCenterDimension;
DialogField     dialogFieldCompanyDimension;

/// <summary>
/// Provides a look-up interaction for the cost center dimension attribute lookup controls.
/// </summary>
/// <param name="_dimensionValueControl">
/// The <c>FormStringControl</c> enumeration value that triggers this event.
/// </param>
public void costCenterDimensionValueLookup(FormStringControl _dimensionValueControl)
{
    if (_dimensionValueControl != null)
    {
 DimensionValueLookupHelper::lookupDimensionValues(DimensionAttribute::findByLocalizedName('Cost_Center', false, SystemParameters::find().SystemLanguageId), _dimensionValueControl);
    }
}

/// <summary>
/// Provides a look-up interaction for the Company dimension attribute lookup controls.
/// </summary>
/// <param name="_dimensionValueControl">
/// The <c>FormStringControl</c> enumeration value that triggers this event.
/// </param>
public void companyDimensionValueLookup(FormStringControl _dimensionValueControl)
{
    if (_dimensionValueControl != null)
    {
DimensionValueLookupHelper::lookupDimensionValues(DimensionAttribute::findByLocalizedName('Company', false, SystemParameters::find().SystemLanguageId), _dimensionValueControl);
    }
}

/// <summary>
/// Modifies a property of field control.
/// </summary>
protected void modifyProperty()
{ 
    this.overrideDialogFieldAlwaysShowLookup(dialogFieldCostCenterDimension);
    this.overrideDialogFieldAlwaysShowLookup(dialogFieldCompanyDimension);
}

/// <summary>
/// Override this method in order to initialize the dialog fields after the fields have been built.
/// </summary>
public void postBuild()
{
    dialogFieldCostCenterDimension =    this.bindInfo().getDialogField(this.dataContractObject(), methodStr(ssyPurchOrderLineContract, parmCostCenterDimensionValue));
    dialogFieldCompanyDimension = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(ssyPurchOrderLineContract, parmCompanyDimensionValue));

    super();
}

protected void modifyOverrideMethod()
{
    this.overrideDialogFieldLookup(dialogFieldCostCenterDimension, methodStr(ssyPurchOrderLineUIBuilder, costCenterDimensionValueLookup));
    this.overrideDialogFieldLookup(dialogFieldCompanyDimension, methodStr(ssyPurchOrderLineUIBuilder, companyDimensionValueLookup));
}

Next, I have to display dimension value with tag description in report, so i write following code in DP class to display this thing (may be there is other good alternative to display this value)

if (costCenterDimensionValue)
{
    qbdsDimensionAttributeValueSetItemViewCostCenter = qbdPurchLine.addDataSource(tableNum(DimensionAttributeValueSetItemView));
qbdsDimensionAttributeValueSetItemViewCostCenter.relations(true);
qbdsDimensionAttributeValueSetItemViewCostCenter.joinMode(JoinMode::ExistsJoin);

    qbdsDimensionAttributeValueSetItemViewCostCenter.addLink(fieldNum(DimensionAttributeValueSetItemView, DimensionAttributeValueSet), fieldNum(PurchLine, DefaultDimension));
qbrCostCenter = qbdsDimensionAttributeValueSetItemViewCostCenter.addRange(fieldNum(DimensionAttributeValueSetItemView, DisplayValue));
qbrCostCenter.value(SysQuery::value(costCenterDimensionValue));

}
if (companyDimensionValue)
{
qbdsDimensionAttributeValueSetItemViewCompany = qbdPurchLine.addDataSource(tableNum(DimensionAttributeValueSetItemView));
qbdsDimensionAttributeValueSetItemViewCompany.relations(true);
qbdsDimensionAttributeValueSetItemViewCompany.joinMode(JoinMode::ExistsJoin);

qbdsDimensionAttributeValueSetItemViewCompany.addLink(fieldNum(DimensionAttributeValueSetItemView, DimensionAttributeValueSet), fieldNum(PurchLine, DefaultDimension));
qbrCompany = qbdsDimensionAttributeValueSetItemViewCompany.addRange(fieldNum(DimensionAttributeValueSetItemView, DisplayValue));
qbrCompany.value(SysQuery::value(companyDimensionValue));

}

Happy DAXing !!!!