When a user clicks Create Shipment on the Sales Order screen, I want to update each line of the Sales Order with the current date if the line was shipped.
I tried 10 different ways to do this. The easiest way I though of was to use the SOShipLine Row Persisting or Row Persisted method on the Shipments graph extension. In those methods, I tried to get the SOLine related to the SOShipmentLine being saved to the DB and update the SOLine custom field. This throws an error the the SOLine is already updated and the update to SOLine is rolled back.
My next approach is to override the CreateShipmentIssue method that is called when you click Create Shipment. I am invoking the method, then trying to update the SOLine after the method has been invoked.
After the method has been invoked, I try to get the SOShipLine where the SOLine has the SOShipLine.origOrderNbr, SOShipLine.origLineNbr, and SOShipLine.origOrderType fields.
However, the select returns null. I think this is because the Shipment has not been committed yet.
My question is, how and where can I capture the shipment lines that were processed and go back to the Sales Order lines to update them?
This is my override. Note that it fires, but the Shipment doesn’t seem to be committed yet, so the SOShipLine comes back null.
public delegate IEnumerable CreateShipmentIssueDelegate(PXAdapter adapter, [PXDate] DateTime?
shipDate, [PXInt] int? siteID, [PXDate] DateTime? endDate);
[PXButton(CommitChanges = true), PXUIField(DisplayName = "Create Shipment", MapEnableRights = PXCacheRights.Select)]
[PXOverride]
public virtual IEnumerable CreateShipmentIssue(PXAdapter adapter, [PXDate] DateTime?
shipDate, [PXInt] int? siteID, [PXDate] DateTime? endDate, CreateShipmentIssueDelegate baseMethod)
{
var result = baseMethod.Invoke(adapter, shipDate, siteID, endDate);
foreach (SOLine line in Base.Transactions.Select())
{
SOShipLine shipLine = SelectFrom<SOShipLine>
.Where<SOShipLine.origOrderNbr.IsEqual<@P.AsString>
.And<SOShipLine.origLineNbr.IsEqual<@P.AsInt>>
.And<SOShipLine.origOrderType.IsEqual<@P.AsString>>>
.View.Select(Base, line.OrderNbr, line.LineNbr, line.OrderType);
if (shipLine != null)
{
SOShipment shipment = SelectFrom<SOShipment>
.Where<SOShipment.shipmentNbr.IsEqual<@P.AsString>
.And<SOShipment.shipmentType.IsEqual<@P.AsString>>>
.View.Select(Base, shipLine.ShipmentNbr, shipLine.ShipmentType);
if (shipment.Confirmed == true && shipLine.ShippedQty > 0)
{
SCGCSOLineExt ext = line.GetExtension<SCGCSOLineExt>();
if (ext != null)
{
if (ext.UsrCreatedShipmentDate != null)
{
ext.UsrCreatedShipmentDate = PX.Common.PXTimeZoneInfo.Now;
Base.Transactions.Update(line);
}
}
}
}
}
return result;
}