Skip to main content

My company has multiple warehouses.  I have added custom code in a SalesOrderEntry Extension to find the closest warehouse that has a requested item, if it isn’t available at the customer’s default warehouse.  If there isn’t enough inventory at any of our locations, a line is created to add the short quantity to the item default warehouse (where the item is manufactured).

The code works if there is enough inventory to fill the item, but if there isn’t enough I get a line type error.  Our item classes are set to allow negative quantities.  I have manually entered the lines the way the code does it and it works manually.  In debug all fields are filled in, including line type.

Example:

Customer orders 200 widgets from location X

Inventory gets checked and 61 widgets are available in default warehouse Y

New line is created for the 61 widgets

Another new line is created for the remaining 139 widgets

Original line is deleted

Line Type Error occurs when the screen is saved

Code:

var tagLine = createSOLineSplit(row, defaultSiteID, requiredAmount);

 

 public SOLine createSOLineSplit(SOLine oldObject, int? siteID, decimal? orderQty)
 {
     SOLine newObj = (SOLine)Base.Transactions.Insert(new SOLine()
     {
         InventoryID = oldObject.InventoryID,
         BranchID = oldObject.BranchID,
         SiteID = siteID,
         IsFree = oldObject.IsFree,
         ManualDisc = oldObject.ManualDisc,
         LineType = oldObject.LineType,
         Operation = oldObject.Operation,
         AutoCreateIssueLine = oldObject.AutoCreateIssueLine,
     });
     newObj.OrderQty = orderQty;
     return (SOLine)Base.Transactions.Cache.Update(newObj);
 }

Trace:

 

 

Thank-you for any direction you can give me.

I would guess it’s having a problem with you inserting all that data at once shot. When you do it manually, you’re changing one field value at a time. To simulate this, you can use code like this:

SOLine newObj = Base.Transactions.Insert();
Base.Transactions.SetValueExt<SOLine.inventoryID>(newObj, oldObject.InventoryID);
// other fields

Base.Transactions.Update(newObj);

This should call all the events as they would be when doing it manually.


This worked.  Thank-you again Daryl!  As always your response is spot on.


Reply