Skip to main content
Solved

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


Forum|alt.badge.img

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

Best answer by Giri K

@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);

                }
            }
        }

View original
Did this topic help you find an answer to your question?

7 replies

Forum|alt.badge.img+1
  • Pro I
  • 59 replies
  • Answer
  • March 13, 2024

@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);

                }
            }
        }


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 15 replies
  • March 13, 2024

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


Forum|alt.badge.img+1
  • Pro I
  • 59 replies
  • March 13, 2024

@fmrubi11 give [PXDefault] attribute to field


Forum|alt.badge.img
  • Author
  • Jr Varsity II
  • 15 replies
  • March 13, 2024

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


Forum|alt.badge.img+1
  • Pro I
  • 59 replies
  • March 14, 2024

@fmrubi11 

Try this attribute in Field 

[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]


Leonardo Justiniano
Jr Varsity II
Forum|alt.badge.img+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


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

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings