Hi, this should be simple but I must be misunderstanding something fundamental to Acumatica development.
I want to create a stock item and I have the following code:
InventoryItemMaint graphStock = PXGraph.CreateInstance<InventoryItemMaint>();
InventoryItem newInvItem = new InventoryItem();
newInvItem.InventoryCD = "TEST2";
newInvItem.Descr = "TEST2";
newInvItem.ItemClassID = 49;
graphStock.Item.Current = graphStock.Item.Insert(newInvItem);
graphStock.Actions.PressSave();
I set the ItemClassID and when I call graphStock.Item.Insert(newInvItem) the Acumatica Framework refeshes the newInvItem object and sets fields such as ItemType, ValMethod and BaseUnit.
Then I set the Current object and perform the Save Action, all basic stuff.
The problem is this, if the ItemClass doesn’t have a Default Warehouse then the code above works fine and the stock item is created. However, if the ItemClass does have a Default Warehouse then the code returns the following error:
Error: Inserting 'Inventory Item Currency Settings' record raised at least one error. Please review the errors.'
The InnerFields shows:
"DfltSiteID"
The InnerMessages shows:
"An error occurred during processing of the field Default Warehouse value 159 Error: An error occurred during processing of the field Inventory ID value -214748364 Error: Inventory ID '-2147483647' cannot be found in the system. Please verify whether you have proper access rights to this object."
If I create stock items in the UI then everything works fine, whether the ItemClass contains a default warehouse or not. Up until this point I had thought that calling graphStock.Item.Insert(newInvItem) or graphStock.Item.Update(newInvItem) would refresh the object in the same way that the UI would but this doesn’t seem to be the case.
Can anyone explain what is happening? Does anyone know what I need to do to fix this problem? How I can select an ItemClass and update the InventoryItem fully?
A screen shot of the ItemClass screen, when Default Warehouse is blank my code works, if a Default Warehouse is enter my code fails :(
Thanks
Steve