Search code examples
axaptadynamics-ax-2012

Field refreshing after changing record


I'm working on Microsoft AX 2012. I have weird problem, I got list page with 5 records from VendTrans table. I have created a method for getting Dimension on VendTrans table in my form Data Sources.

public display DimensionValue getDimensionValue(VendTrans _vendTrans)
{    
    dimAttrValueSet = DimensionAttributeValueSet::find(VendTrans.DefaultDimension);    
    select dimAttrValueSetItem
        where   dimAttrValueSetItem.DimensionAttributeValueSet      == dimAttrValueSet.RecId
    join dimAttrValue
        where   dimAttrValue.RecId                                  == dimAttrValueSetItem.DimensionAttributeValue
    join dimAttribute
        where   dimAttribute.RecId                                  == dimAttrValue.DimensionAttribute
        &&      dimAttribute.Name                                   == 'NAME';

    return dimAttrValue.getValue();
}

On my form I have created a field. Data Source is set to VendTrans (table) and DataMethod is set to "getDimensionValue".

And now after changing chosen record on my list page, this field is refreshing for all records.

For example my dimension value for 1st record is "AAA" and for 2nd record is "BBB". When 1st record is chosen this field value for all 5 records would be "AAA". After chosing 2nd record value is "BBB" for all 5 records.

It's clear that I want value for every record in a field for it, without any refresh afther changing records ...


Solution

  • You have two problems:

    1. Use _vendTrans.DefaultDimensioninstead of VendTrans.DefaultDimension in line 3.
      That is why the same value is in all lines, you are referencing the active record in stead of the record of the grid line.
    2. Use display method caching to improve performance of the form.

    To fix both move the method to the VendTrans table to enable caching:

    [SysClientCacheDataMethodAttribute(true)]
    public display DimensionValue getDimensionValue()
    {
        dimAttrValueSet = DimensionAttributeValueSet::find(this.DefaultDimension);
        ...
    }