Retail Statement Posting > Function InventTrans.inventMovement has been used incorrectly.

Open Retail Statement > Posting open statement gives error “Function InventTrans.inventMovement has been used incorrectly”

We are experiencing this error at one of our client’s production environment (Dynamics AX 2012 R2 CU7). I have debugged the issue thoroughly and found that while constructing the InventMovement class for one of the movements (InventTrans), the originator (Table InventTransOrigin method call to method: originator(), queries

respective table for related data, in our case RetailtransactionSalesTrans table since 150 (Statement) in ReferenceID field in InventTransOrigin table) is not found.

Later while returning this movement object, its originator (buffer()) is validated and since not initialized, the IF condition is not met, so no variable is returned, the underlying condition is evaluated, which is met as true and gives the error. Code listing is provided for the referece as follows;

Code Listings and Flow

Process Knowledge

As far as I have investigated and inquired my colleagues, the process is that,

First all sales transactions / movements are compiled / calculated

System then generates an SO (on runtime)

When posting the SO, InventTrans aare generated to post the inventory physically

Posting is completed

Now during this process and somewhere in the InventUpdate classes, the invetMovement method is called which then looks that the request is from Statement (150) with Retail congif key ON, tries to find a record in RetailTransactionSalesTrans which is not there.

Hence the issue is identified, but the question is, if a Retail Statement is open, should such statements and their transactions have records in InventTrans and InventTransOrigin ?

How is it possible that ITO has reference category to 150 (retail statement) and reference ID = valid retail statement (open state) has no reference record in RetailTransactionSalesTrans.

Is it a bug ? Is their any hotfix available ? If it is not, how to resolve it ? Any one else experienced it ?

Kindly help me regarding this

Hi Abdul,

Is your issue resolved ? I’m also getting same kind of error. If you find any solution for this, pls update me.

Thanks,

Maria

Hi,

We have experienced the same issue when posting statements. We found that for certain items there was inventory transactions with the Issue Status = Reserved ordered. The same lines also had origin reference = Statement but no number specified.

What we did (in our test environment) was to simply delete these lines in InventTrans and that solved the problem. Once the lines was deleted we could post the statements without any errors. I am, at the moment, not sure what effect this possibly has on the inventory etc. but I am investigating it. I do not think it will have an effect since the lines was only reserved against a purchase order.

Any way this seems to fix the error but maybe not explain why it happened in the first place.

Cheers

Love

Hello,

We just had the error at one of our customers running AX2012 R3 CU10 when doing a sales credit invoice.
Turned out that it was caused by some faulty inventory transactions, referencing to retail sales transactions that didn’t exist.

Thanks Love for the clue! :slight_smile:

We’re still not sure what caused the issue.

I fixed it with this script:

// CJ 2016-11-09
static void TYDfixMissingRetailInventoryTrans(Args _args)
{
InventTrans inventtrans, delinventtrans;
InventTransOrigin InventTransOrigin, delInventTransOrigin;
retailtransactionsalestrans retailtransactionsalestrans;
ItemId itemid = “47459”;
int x;
;
while select inventtrans where
inventtrans.ItemId == “47459” &&
!inventtrans.DatePhysical &&
!inventtrans.DateFinancial
join firstonly inventtransorigin where
InventTransOrigin.RecId == inventtrans.InventTransOrigin &&
InventTransOrigin.ReferenceCategory == InventTransType::Statement
{
select firstonly retailtransactionsalestrans where
retailtransactionsalestrans.inventTransId == inventtransorigin.InventTransId;

if(!retailtransactionsalestrans)
{
ttsBegin;
select forupdate firstonly delinventtrans where
delinventtrans.RecId == inventtrans.RecId;

delinventtrans.delete();

select forUpdate firstOnly delInventTransOrigin where
delInventTransOrigin.RecId == InventTransOrigin.RecId;

delInventTransOrigin.delete();
ttsCommit;

info(delinventtrans.itemid);

x++;
}
}
info(strFmt("%1 records deleted",x));

new InventSumReCalcItem(itemid,true,CheckFix::Fix).updateNow();

}