Search code examples
acumatica

Rest Api field Shipvia incorrect value


When we create soshipment with API, the field SHIPVIA is ok, But when we add some solines, the fielshipvia is ko.

In this example, we have "ROUTE" in the order, but we put "TRAIN" in the shipment. It's a pity that the webservice is not working properly

{"CustomerID": {"value": "HOTELLAC"}, "Hold": {"value": true}, "ShipmentDate": {"value": "2023-07-04T00:00:00+00:00"}, "Type": {"value": "I"},"Operation": {"value": "I"},"WarehouseID": {"value": "PARIS"}, "Details": [{"OrderNbr": {"value": "000908"}, "OrderType": {"value": "SO"},"OrderLineNbr": {"value": 1},"ShippedQty": {"value": 1}}], "ShipVia": {"value": "TRAIN"}}

I use this URL https://XXXXXXXX/entity/FFY/20.200.001/Shipment?$expand=Details


Solution

  • When we add an order to a shipment, the shipment's ShipVia is defaulted from the order. To avoid this, we need to override SetShipmentFieldsFromOrder function on SOShipmentEntryGraph. I tested this solution on 23R1.

    using System;
    using PX.Data;
    using PX.Objects.SO;
    
    namespace PX.Objects
    {
       public class SOShipmentEntryExt : PXGraphExtension<SOShipmentEntry>
       {
        public delegate bool SetShipmentFieldsFromOrderDelegate(SOOrder order, SOShipment shipment,
            int? siteID, DateTenter code hereime? shipDate, string operation, SOOrderTypeOperation orderOperation,
            bool newlyCreated);
    
        [PXOverride]
        public virtual bool SetShipmentFieldsFromOrder(SOOrder order, SOShipment shipment,
            int? siteID, DateTime? shipDate, string operation, SOOrderTypeOperation orderOperation,
            bool newlyCreated, SetShipmentFieldsFromOrderDelegate baseMethod)
        {
            // Save the ShipVia, we need to restore it after the shipment is created.
            var oldShipVia = order.ShipVia;
            if (newlyCreated)
            {
                order.ShipVia = shipment.ShipVia;
            }
    
            var result = baseMethod(order, shipment, siteID, shipDate, operation, orderOperation, newlyCreated);
    
            if (newlyCreated)
            {
                // Restore ShipVia on the order, without this Shipment's ShipVia will overwrite it.
                order.ShipVia = oldShipVia;
            }
    
            return result;
        }
    }
    

    }