Skip to main content

I’m planning to make the SOOrder.ShipVia field required and want to add an error message to help our employees.

I have found a couple of examples but am working with this right now:

namespace PX.Objects.SO
{
public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
{
#region Event Handlers

protected void SOOrder_ShipVia_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs e)
{

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.  

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.

 

Adding Validation Without Utilizing Code Files (greytrix.com)


@abrunner78 ,

Here’s the documentation on how to make a field required/mandatory:

To Make a Field Mandatory

Little more references:

Acumatica Making a custom field required - Stack Overflow

Low/ no code: Tips & Tricks Using Acumatica's Low-Code/No-Code, section: make a field mandatory

 

Hope it helps


@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. 

Here are a few more images of the current config.

I have also tried changing

sPXDefault(PersistingCheck = PXPersistingCheck.Nothing)]

to

sPXDefault(PersistingCheck = PXPersistingCheck.NullOrBlank)]

 

 


@abrunner78 to make it required at Graph level, consider attaching cacheAttached event handler

c# - How do you mark a field as required in Acumatica? - Stack Overflow

How to add graph extension: To Create a Graph Extension

cacheAttached: Overriding Attributes of a DAC field in the Graph

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.
 


PXUIRequired(typeof(Where<Selector<SOOrder.orderType, SOOrderTypeExt.usrHWDERequireShipVia>, Equal<True>>))]
PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
PXMergeAttributes(Method = MergeMethod.Append)]
protected virtual void _(Events.CacheAttached<SOOrder.shipVia> e)
{
}

If you want to make it always required, just remove the PXUIRequired attribute. PXDefault sets the field as required.


just remove the PXUIRequired attribute. PXDefault sets the field as required.

PXDefault with PersistingCheck set to Nothing will NOT work as expected.


For whatever reason, I believe the RowSelected event handler is the only one that allows you to set errors on the Ship Via field.


Reply