Solved

Conditionally make custom field on Sales Order mandatory when sales order type = "XR"

  • 13 March 2024
  • 7 replies
  • 97 views

Userlevel 1

I have custom fields on Sales order header. I want the fields active and mandatory only when order type is “XR”. Please assist how i can achieve that in Acumatica customization. The fields will be invisible if order type is any other

icon

Best answer by Giri K 13 March 2024, 19:03

View original

7 replies

Badge +11

Using [PXUIRequired] would possibly be a less verbose option, as indicated here.

Userlevel 6
Badge +4

Hi @fmrubi11 

Do the validation on RowPersisting checking for the order type XR.

[PXLocalizable()]
public static class Messages
{
public const string FieldErrorMessage = "Field Error Message";
public const string ErrorMessage = "Error Message";
}

public static class SOOrderTypeConstantsExt
{
public static string XR { get { return new xr().Value; } }

public class xr : PX.Data.BQL.BqlString.Constant<xr>
{
public xr() : base("XR") { }
}
}

protected void _(Events.RowPersisting<SOOrder> e)
{
if (e.Row != null)
{
PXEntryStatus entryStatus = e.Cache.GetStatus(e.Row);
if (entryStatus == PXEntryStatus.Inserted || entryStatus == PXEntryStatus.Updated)
{
SOOrder so = e.Row as SOOrder;
SOOrderExt ext = e.Row.GetExtension<SOOrderExt>();
if(so.OrderType == SOOrderTypeConstantsExt.XR)
{
if(ext.UsrField == null /* && <YOUR BUSINESS RULE> */)
{
e.Cache.RaiseExceptionHandling<SOOrderExt.usrField>(e.Row, null, new PXSetPropertyException(Messages.FieldErrorMessage, PXErrorLevel.Error));
throw new PXException(Messages.ErrorMessage);
}
}
}
}
}

Happy to help

Userlevel 4
Badge +1

@fmrubi11 

Try this attribute in Field 

[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]

Userlevel 1

setting [PXDefault()] in the DAC will also be trigger even when order type is not “XR” and will not allow saving of document

Userlevel 4
Badge +1

@fmrubi11 give [PXDefault] attribute to field

Userlevel 1

Thank you, this worked in making it visible or invisible depending on order type. However the fields still not mandatory

Userlevel 4
Badge +1

@fmrubi11 

Create Extension graph for SOOrderEntry and add below code

 

 public virtual void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected baseHandler)
        {
            Base.Document.View.RequestRefresh();
            if (baseHandler != null)
                baseHandler(cache, e);
            var row = (SOOrder)e.Row;
            if (row == null)
                return;

            if(row!=null)
            {
                //SOOrderExtension is Extension DAC for SO Header table
                SOOrderExtension soExt = row.GetExtension<SOOrderExtension>();

                if (row.OrderType=="XR")
                {
                    PXUIFieldAttribute.SetVisible<SOOrderExtension.FieldName>(cache, null, true);
                    PXDefaultAttribute.SetPersistingCheck<SOOrderExtension.FieldName>(cache, null, PXPersistingCheck.NullOrBlank);

                }
                else
                {
                    PXUIFieldAttribute.SetVisible<SOOrderExtension.FieldName>(cache, null, false);
                    PXDefaultAttribute.SetPersistingCheck<SOOrderExtension.FieldName>(cache, null, PXPersistingCheck.Nothing);

                }
            }
        }

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved