I have a use case where we do not want to update the ShipDate and RequestDate fields on the SOLines when the Requested On date in the header is changed.
When an order is shipped and lines are placed on Backorder, the SO is changed to status of Backorder and the Requested On date in the header gets changed, and it automatically updates the fields in the Lines.
Here is what I have tried. When the Requested On date in the SO header is updated, I store the original values of the ship and request dates in a dictionary.
Then when the SOLine is updated, I am trying to set the dates back to the original dates from the dictionary.
However, the SOLine_RowUpdated (and SOLine_RowUpdating) events do not fire. I think this is because the SOLines are not being updated in the graph, but through some other code, maybe a graph extension?
I tried to do an override on public virtual void SOOrder_ShipDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e) to try to stop it from happening. But my override fires AFTER the original event occurs. A popup is generated and if the order is on back order or the lines are not completed, I don’t want the order to automatically update the lines.
Here’s my code:
public Dictionary<int?, DateTime?> origReqDates = new Dictionary<int?, DateTime?>();
public Dictionary<int?, DateTime?> origShipDates = new Dictionary<int?, DateTime?>();
protected void SOOrder_RowUpdating(PXCache cache, PXRowUpdatingEventArgs e)
{
var row = (SOOrder)e.Row;
foreach (SOLine line in Base.Transactions.Select())
{
origReqDates.Add(line.LineNbr, line.RequestDate);
origShipDates.Add(line.LineNbr, line.ShipDate);
}
}
protected void SOLine_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler)
{
if (InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (SOLine)e.Row;
SOOrder order = Base.Document.Current;
if (row.Completed == true || order.Status == SOOrderStatus.BackOrder) return;
bool foundReqDate;
bool foundShipDate;
foundReqDate = origReqDates.TryGetValue(row.LineNbr, out DateTime? reqDateToUse);
foundShipDate = origShipDates.TryGetValue(row.LineNbr, out DateTime? shipDateToUse);
if (foundReqDate)
{
cache.SetValue<SOLine.requestDate>(row.LineNbr, reqDateToUse);
}
if (foundShipDate)
{
cache.SetValue<SOLine.shipDate>(row.LineNbr, shipDateToUse);
}
}
//NOT WORKING AS HOPED
//[PXOverride]
// public virtual void SOOrder_ShipDate_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
// {
// cache.SetDefaultExt<SOOrder.invoiceDate>(e.Row);
// if (((SOOrder)e.Row).Status == SOOrderStatus.BackOrder)
// {
// return;
// }
// DateTime? oldDate = (DateTime?)e.OldValue;
// if (oldDate != ((SOOrder)e.Row).ShipDate)
// {
// if (Base.Document.View.Answer == WebDialogResult.None && !Base.IsMobile && ((SOOrder)e.Row).ShipComplete == SOShipComplete.BackOrderAllowed && Base.HasDetailRecords())
// Base.Document.Ask(GL.Messages.Confirmation, Messages.ConfirmShipDateRecalc, MessageButtons.YesNo);
// }
// }
I don’t know where I can intercept the changes that are occurring and stop the dates from changing on the Lines.
Any ideas?
