Search code examples
acumatica

Delete row from SOShipLine in Acumatica Framework


Good day,

I need to delete a row from SOShipLine on Shipments screen

screenshot of action

I am working on an extension of SOShipmentEntry and trying to do the following to remove the row

            PXResultset<SOShipLine> shipLines = SelectFrom<SOShipLine>.InnerJoin<SOShipment>.On<SOShipLine.shipmentNbr.IsEqual<SOShipment.shipmentNbr>>
            .Where<SOShipLine.shipmentNbr.IsEqual<@P.AsString>>.View.Select(Base, shipment.ShipmentNbr);

        List<Linelevel> lineLevels = osr.Transaction.Transaction.Order.LineLevel;


        foreach (SOShipLine shipLine in shipLines)
        {
            Linelevel lineLevel = lineLevels.Find(lineNbr => lineNbr.POLineNum == shipLine.LineNbr);
            if (lineLevel != null)
            {
                shipLine.ShippedQty = lineLevel.PickedQuantity;
            } else
            {
                Base.Transactions.Cache.Delete(shipLine);
            }
        }

but when I get to the point where I want to delete the row it generates an exception where it asks me that the key cannot be null


Solution

  • Try working directly with the Transactions view instead of querying the data with PXSelect.

    // This is no longer needed - retrieve from the Transactions view instead
    //PXResultset<SOShipLine> shipLines = SelectFrom<SOShipLine>.InnerJoin<SOShipment>.On<SOShipLine.shipmentNbr.IsEqual<SOShipment.shipmentNbr>>
    //  .Where<SOShipLine.shipmentNbr.IsEqual<@P.AsString>>.View.Select(Base, shipment.ShipmentNbr);
    
    List<Linelevel> lineLevels = osr.Transaction.Transaction.Order.LineLevel;
    
    // Cycle through the records returned directly from the Transactions view
    //foreach (SOShipLine shipLine in shipLines)
    foreach (SOShipLine shipLine in Base.Transactions.Select())
    {
        Linelevel lineLevel = lineLevels.Find(lineNbr => lineNbr.POLineNum == shipLine.LineNbr);
        if (lineLevel != null)
        {
            shipLine.ShippedQty = lineLevel.PickedQuantity;
        } else
        {
            // Generally speaking, work with the view instead of the cache when possible
            //Base.Transactions.Cache.Delete(shipLine);
            Base.Transactions.Delete(shipLine);
        }
    }
    // After your logic completes, make sure the user has to press Save or you do it for them
    Base.Save.Press();
    

    I typically only work directly with the cache when I'm working with some other data that isn't in a view, like pushing a reference value into a record managed elsewhere. Even then, I prefer to create a view in the graph extension and work with that.