Friday, May 1, 2015

Financial dimension lookup

While developing in AX "lookups" are the most common requirements you may come across. However, sometimes you may have to link your customized lookup to non-conventional datasets such as "Financial Dimensions". 
This post will show you how to create custom lookup listing one of "Financial Dimension" on report dialog. For this requirement it requires "UI Builder" class.

This customized lookup function will be using "DimensionDefaultingLookup" from.

Contract Class declaration : 

[
    DataContractAttribute,  SysOperationContractProcessingAttribute(classStr(xxxxReportUIBuilder))    
]
public class xxxxReportContract
{
    Name    dimensionValue;
}

Contract parameter :

[
    DataMemberAttribute(identifierStr(dimensionValue)),
    SysOperationLabelAttribute(literalstr('@SYS3794')),
    SysOperationDisplayOrderAttribute('1')
]
public Name parmFinDimLocation(Name _dimensionValue = dimensionValue)
{
    dimensionValue = _dimensionValue;
    return dimensionValue;
}

UI Builder Class declaration : 

public class xxxxReportUIBuilder extends SrsReportDataContractUIBuilder
{
    
}

Lookup function : 

public void lookupFDLocation(FormStringControl _dimensionValueControl)
{
    Args                e;
    FormRun             lookupFormRun;
    DimensionAttribute  dimensionAttribute;

    Name dimensionAttributeName;

    dimensionAttributeName = "Location";

    if (_dimensionValueControl != null)
    {
        // Construct arguments for the custom lookup
        e = new Args();
        e.name(formStr(DimensionDefaultingLookup));
        e.lookupValue(_dimensionValueControl.text());
        e.caller(_dimensionValueControl);

        dimensionAttribute = DimensionAttribute::findByLocalizedName(dimensionAttributeName, false, SystemParameters::find().SystemLanguageId);

        e.lookupField(dimensionAttribute.ValueAttribute);
        e.record(dimensionAttribute);

        // Do the lookup
        lookupFormRun = classFactory.formRunClass(e);
        lookupFormRun.init();

        _dimensionValueControl.performFormLookup(lookupFormRun);
    }
}

PostBuild function : 

public void postBuild()
{
    DialogField dimensionAttributeValue;

    super();

    dimensionAttributeValue = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(xxxxReportContract, parmFinDimLocation));

    if (dimensionAttributeValue)
    {
        dimensionAttributeValue.lookupButton(2);
    }
}


PostRun function : 

public void postRun()
{
    Dialog      dialogLocal = this.dialog();
    DialogField dialogField;

    super();
    
    dialogLocal.dialogForm().formRun().controlMethodOverload(false);

    // Override the lookup for parmDimensionAttribute contract parameter with dimensionAttributeLookup of this class.
    dialogField = this.bindInfo().getDialogField(this.dataContractObject(), methodStr(xxxxReportContract, parmFinDimLocation));

    dialogField.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(xxxxReportUIBuilder, lookupFDLocation), this);

}

No comments:

Post a Comment