Skip to main content
Solved

Trying to prevent Ship Date and Request Date on SOLine from being updated

  • November 19, 2024
  • 9 replies
  • 136 views

Joe Schmucker
Captain II
Forum|alt.badge.img+3

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?

Best answer by darylbowman

Also, this seems to cause an error

You don’t need [PXOverride]

9 replies

Forum|alt.badge.img+9
  • Captain II
  • November 19, 2024

Hi ​@Joe Schmucker 


have you tried to set this through the workflow by adding a field assignment upon the transition to back order?

 

Aleks


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • November 20, 2024

Hi ​@aiwan  I will look into using a workflow.  I don’t like using workflows because If I modify the SO screen in my project, the customer cannot modify the workflow for that screen in their own project, or one of them gets ignored.  

I wish workflows could be merged when publishing multiple projects modifying the same screen the way screen changes are merged.  I can only imagine though that the logic to do that would be immensely complicated.

 


Forum|alt.badge.img+9
  • Captain II
  • November 20, 2024

After the extension is published and in the website /bin folder could the customer use a second level extension to update/amend the workflow which was changed in the primary extension? Just a question, I haven’t tried this.


darylbowman
Captain II
Forum|alt.badge.img+16

I think you were on the right track, but your event override is wrong. Try this:

protected virtual void _(Events.FieldUpdated<SOOrder.shipDate> e, PXFieldUpdated b)
{
e.Cache.SetDefaultExt<SOOrder.invoiceDate>(e.Row);

if (1 == 0) // Could be conditionally activated
{
DateTime? oldDate = (DateTime?)e.OldValue;
if (oldDate != ((SOOrder)e.Row).ShipDate)
{
if (Document.View.Answer == WebDialogResult.None && !this.IsMobile && ((SOOrder)e.Row).ShipComplete == SOShipComplete.BackOrderAllowed && HasDetailRecords())
Document.Ask(GL.Messages.Confirmation, Messages.ConfirmShipDateRecalc, MessageButtons.YesNo);
}
}
}

Usually, you’d call b?.Invoke(e.Cache, e.Args); to execute the base event, but in your situation, it would be far easier to just not call it and rewrite the code how you want it.


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • November 20, 2024

@darylbowman  Trying it now.  However, if (1 == 0) will always be false.  Were you expecting I’d put my own condition there?

Also, this seems to cause an error:

 


darylbowman
Captain II
Forum|alt.badge.img+16

Yeah, if you want it to ask sometimes, you could. Otherwise, just rip it out.


darylbowman
Captain II
Forum|alt.badge.img+16
  • Answer
  • November 20, 2024

Also, this seems to cause an error

You don’t need [PXOverride]


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • January 23, 2025

Hi ​@Joe Schmucker were you able to find a solution? Thank you!


Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • January 23, 2025

Hi friends. 

I ended up creating custom fields to store the original dates.  Then every time the SO got updated, I would re-populate the Requested date to the original date (including line items).  

We found out that the Requested Ship date was being changed by some process that had been setup in the Shopify program.  I ended up not needing to do anything code-wise to stop the date from being modified.  This issue took until a couple of weeks ago to solve.  It took 3 months to solve.

I am now ripping out all the customizations I did as we don’t need them any longer.