var row = (SOOrder)e.Row; if(row == null) { string errorMsg = "Ship Via Cannot be Empty"; throw new PXSetPropertyException(errorMsg, PXErrorLevel.Warning); }
}
#endregion
Not being a programmer, I’m sure there is something simple missing, but I would appriciate the help.
Page 1 / 1
I think you might want to change your if conditional to something like this (not tested):
if(string.IsNullOrEmpty(row?.ShipVia)) { ... }
I don’t know if the field verifying events can actually have a null value for row but the ? in the ShipVia check will catch that like you want it to. Otherwise this will primarily check for instances where nothing is in ShipVia and then your exception will get thrown.
Hi @abrunner78 ,
We can add validation without any coding. Refer to the blog below.
@PorchlightZach, I see what you were doing and will keep that in mind. Unfortunately, that code didn’t work as is and I might need to loop my VAR intro the conversation.
@jinin and @RohitRattan88, I had been able to use the Required column in the Fields section to make the field required. But for what ever reason I only get a modal error upon saving and no error/warning at the Ship Via field or Shipping tab.
I know it is slowing leaning more towards programming/development, but I think it is light and good exposure to understand customizations.
Good luck
When I’m working on a graph extension to show an error before saving, I’ve had success putting the code in a RowUpdating event. Something like this:
protected virtual void SOOrder_RowUpdating(PXCache cache , PXRowUpdatingEventArgs e , PXRowUpdating InvokeBaseHandler) { var order = (SOOrder)e.Row; if (string.IsNullOrEmpty(order.ShipVia)) { cache.RaiseExceptionHandling<SOOrder.shipVia>(order, order.ShipVia, new PXSetPropertyException("ShipVia cannot be empty" , PXErrorLevel.Error)); }
InvokeBaseHandler?.Invoke(cache, e); }
Unfortunately, it doesn’t work for ShipVia like other fields I’ve used this on.
I looked into this a bit more and can see the SOOrder DAC is already specifying PersistingCheck = PXPersistingCheck.Nothing for the ShipVia’s PXDefault Attribute. Part of the reason it does this is certainly related to the fact that if ShipVia is null, Acumatica automatically checks the “Will Call” box. If you use Will Call for some orders, you probably don’t want to force ShipVia to be filled without overriding the PXUIField attribute for WillCall so it is not IsReadOnly = true.
I’ve never tried this, but the Stack Overflow article RohitRattan linked suggests you could include dPXMergeAttributes(Method = MergeMethod.Replace)] near the rPXDefault( … )] change you made. In theory this should replace the base attribute logic with whatever you specify.
If you do this and leave your PXDefault code as is, you’ll lose the existing default behavior that tries to pull in the ShipVia from the customer location tied to the order.
That makes me think, why not solve this problem by specifying a default ShipVia for all of your customer classes? That’d prevent an empty ShipVia for all new customers. As for your existing customers, the Customer Locations screen (AR3030P1) can be modified to allow mass update of the ShipVia field. It isn’t the same as throwing an error to force the end user to think about it but at least you won’t have a bunch of orders set to WillCall on accident.
@RohitRattan88 Thanks for the resources. Even prior to posting this I had been looking through the help articles and searching for anything I could find online. But, it seems, as @PorchlightZach pointed out, this wasn’t the simple customization I was expecting it to be and I’ll need to look into replacing the current handler.
Zach, due to the way we have our ecommerce platform, 3PLs, and customer communications set up we expect a ShipVia code, but cannot preset a default since we fulfill parcel and LTL orders.
I’ll keep on looking into this and plan to chat with our VAR next week. Once I figure it out I’ll update the post with the code.
Hi @abrunner78 were you able to find a solution? Thank you!
We have a flag on the sales order type that requires ship via (SOOrderTypeExt.usrHWDERequireShipVia) . I use a Cache Attached event to add this in my SOOrderEntry graph extension.