Skip to main content
Answer

Preventing a Sales Order from being taken off hold

  • November 7, 2024
  • 4 replies
  • 151 views

Forum|alt.badge.img+7

I think I’ve been looking at this too long. 24r1

I have set ShipVia to be required through cache attached in my SOOrderEntry extension. I added Required = true to PXUIField and changed the PersistingCheck in PXDefault to NullOrBlank:

[PXMergeAttributes(Method = MergeMethod.Merge)]
[PXUIField(DisplayName = "Ship Via", Required = true)]
[PXDefault(typeof(Search<Location.cCarrierID, Where<Location.bAccountID, Equal<Current<SOOrder.customerID>>, And<Location.locationID, Equal<Current<SOOrder.customerLocationID>>, And<Current<SOOrder.behavior>, NotEqual<SOBehavior.bL>>>>>), PersistingCheck = PXPersistingCheck.NullOrBlank)]
protected virtual void _(Events.CacheAttached<SOOrder.shipVia> e)
{ }

So, in theory, I should not be able to save the record without supplying a shipvia value. But, I can click Remove Hold.

Now, the record is not persisted to the database, but the order is now Off Hold.

And I understand that’s because the action for taking the record off hold is to change the value of Hold to false. And then the action attempts to save the record. And it failed the save the record because of the missing data. But the record has already progressed past On Hold.

Now I’m thinking the best course of action is to put a handler for Hold_FieldUpdating so I can check if we’re trying to leave being on hold and make sure that all required fields have been filled in.

Am I overthinking this?

Best answer by MichaelShirk

@Django you could use an event handler, but I believe the Acumatica approved way (and the cleanest way) of doing this would be to modify the workflow to add a condition where “Remove Hold” wouldn’t be available until a value was added in the Ship Via field. However, the downside of this would be that although the button would be correctly disabled, the user would have no way of knowing that it was the empty Ship Via field that was disabling the action. 
If you want the user to be notified when they click the action button, but not allow it to proceed without a value, then an event handler is probably your best option.
 

4 replies

MichaelShirk
Captain II
Forum|alt.badge.img+5
  • Captain II
  • Answer
  • November 8, 2024

@Django you could use an event handler, but I believe the Acumatica approved way (and the cleanest way) of doing this would be to modify the workflow to add a condition where “Remove Hold” wouldn’t be available until a value was added in the Ship Via field. However, the downside of this would be that although the button would be correctly disabled, the user would have no way of knowing that it was the empty Ship Via field that was disabling the action. 
If you want the user to be notified when they click the action button, but not allow it to proceed without a value, then an event handler is probably your best option.
 


Forum|alt.badge.img+7
  • Author
  • Captain II
  • November 8, 2024

@MichaelShirk - thank you! I figured that the right way would be through workflow but I think that this might be a bug. I pulled up a relatively uncustomized site, created a new sales order and before I selected the customer, I pressed Remove Hold. And the workflow changed the field value and then attempted to save the record - which failed. But the order had already been moved forward.

And I think that’s because the workflow actions aren’t trying to save the record before they do their logic. Typically, when I write an action, the first thing I do is save the record. Then I do the logic and, if it makes sense, I save the record again before returning control to the user.

So I’m thinking that workflow actions need to have an option of trying to save the record first.

It’s also possible that I’ve missed something. :)


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

So I’m thinking that workflow actions need to have an option of trying to save the record first.

They do:

var actionProcessInvoiceAndPayment = context.ActionDefinitions
.CreateExisting<DXSOOrderEntryExt>(g =>
g.processInvoiceAndPayment, a =>
a
.DisplayName("Process Invoice and Payment")
//.IsHiddenWhen(conditions.IsNotInCompletedState)
//.WithCategory(categoryProcessing)
.MapEnableToSelect() or .MapEnableToUpdate() (will disable action if document is readonly)
here*-> .WithPersistOptions(ActionPersistOptions.PersistBeforeAction)
.IsExposedToMobile(true)
.MassProcessingScreen<SOCreateShipment>());

 


Forum|alt.badge.img+7
  • Author
  • Captain II
  • November 8, 2024

Thank you @darylbowman! I figured this was too big of a gap. Just need to convince someone that releaseFromHold needs to have that added.