Today I face the very strange behavior of X++ code.
We develop customization. We generate transfer and issuance through X++.
Logic was very simple,If stock is available then transfer / Issuance or Adjustment journal create otherwise generate error message, We took this decision based of query on Inventsum. It works fine in most of cases but In one case when stock is zero it fails. We create Movement Journal to generate stock in that Item variant. The select query always return Zero stock in posted quantity. Even I get the recid in debug mode and placed in table explorer, Quantity is available in table explore.
This case occurs when got Zero stock in Inventsum table and we try to increase stock by movement journal, other wise select on InventSum works fine.
The query will be very similar
Select * from InventSum where Inventsum.ItemId == line.ItemId && inventSum.invetdimId == line.fromInventiDimId;
This will not work. Even Db synch, Inc Cil, Cache clear done, even Restart the Test server AOS.
I have to switch code from select query to Class InventOnhand. Very similar to following.
inventOnHand = InventOnhand::newParameters(_line.Itemid,_line.FromInventDimId,inventDimParm);
If (inventOnHand.availPhysical() > _line.RequestedQty)
Info( ” Quantity Avalible “);
Info (” Not available “);
Its works perfectly fine. I think InventonHand class is better the do direct query on Inventsum table.