Search code examples
axaptadynamics-ax-2012-r2

Wrong fields reset when method SalesLine.modifiedField is called from code


Take any sales order with a line that has fields SalesLine.Name and SalesLine.ExternalItemId populated.

Then run following job trying to modify any field not related to the two above:

SalesLine sl = SalesLine::findInventTransId('US01-000025', true);
ttsBegin;
sl.CustomerLineNum = 100; //any other field will serve as well
sl.modifiedField(fieldNum(SalesLine, CustomerLineNum)); //causes the issue
sl.update();
ttsCommit;

When the job has completed, both Name and ExternalItemId will be reset.

The issue is caused by line this.axInventDim().isFieldSet(fieldNum(InventDim, ConfigId)) in \Classes\AxSalesLine\isCustExternalItemDescriptionFieldsSet, which always returns true.

As a result, methods AxSalesLine.setName and AxSalesLine.setExternalItemId populate respective fields with default values.

Any advice on the reason it has been coded in Microsoft this way, and the best way to fix this?

P.S. I narrowed down the issue to method \Classes\AxSalesLine\setRetailVariantId that was introduced in R2 CU7


Solution

  • This is a base bug that was resolved 4/30/15 on KB3061573.

    https://fix.lcs.dynamics.com/Issue/Resolved?kb=3061573&bugId=3612128&qc=83c15cd8881ece605195acc30e039142

    I think the full method fix is close to what you have, but the hotfix may also adjust other methods. I hope this hotfix is satisfying knowing you're not crazy.

    protected void setRetailVariantId()
    {
        InventDimCombination    comb;
        InventDim inventDim;
        ;
        comb = InventDimCombination::findVariantId(salesLine.RetailVariantId);
        inventDim = this.axInventDim().inventDim();
        if(comb)
        {
            if (inventDim.InventSizeId != comb.inventDim().InventSizeId)
            {
                this.axInventDim().parmInventSizeId(comb.inventDim().InventSizeId);
            }
            if (inventDim.InventColorId != comb.inventDim().InventColorId)
            {
                this.axInventDim().parmInventColorId(comb.inventDim().InventColorId);
            }
            if (inventDim.InventStyleId != comb.inventDim().InventStyleId)
            {
                this.axInventDim().parmInventStyleId(comb.inventDim().InventStyleId);
            }
            if (inventDim.configId != comb.inventDim().configId)
            {
                this.axInventDim().parmConfigId(comb.inventDim().configId);
            }
        }
    }
    // </RETAIL>