1
votes

I want to perform few validations on Sales order screen, I am comparing the Customer(customerID) field and the Customer Order(CustomerOrderNbr) field and try to give an error message if both the fields match.

I am not a programmer but I tried some code which is giving lot of errors and i'm not able to fix it...

 namespace PX.Objects.SO
{
  public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
  {
        public const string ordernbrErrorMessage = "Customer name and customer number cannot be same.";


    public void SOOrder_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
    {
      if (!ValidateCustomerID(sender, e.Row as SOOrder))
            {
                PXUIFieldAttribute.SetError<SOOrder.customerID>(sender, e.Row, ordernbrErrorMessage);
            }
     }



      public bool ValidateCustomerID(PXCache sender, SOOrder soOrder)
        {
            if (soOrder != null)
            {
                string soCustomerID = PXSelectorAttribute.GetField(sender, soOrder, typeof(SOOrder.customerID).Name, soOrder.CustomerID, typeof(Customer.acctCD).Name) as string; 
                string soCustomerOrderNbr = soOrder.CustomerOrderNbr; 

                if (soCustomerID != null && soCustomerOrderNbr != null)
                {
                    return !soCustomerID.Trim().Equals(soCustomerOrderNbr.Trim(), StringComparison.OrdinalIgnoreCase);
                }
            }             

            return true;

        }
  }
}

And this is my 1st entry with some customer name and order number

enter image description here

And this is my 2nd entry with same customer name and order number

enter image description here

After doing the changes in the code it isn't showing any error message...I restarted the website and checked but no results

1

1 Answers

2
votes

I fixed the syntax errors below. However I would be inclined to think this validation has no practical use case. CustomerID is an integer (number) field in the database that identifies the customer record, usually this is not shown to the user. CustomerOrderNbr is a free form text field that can contain any string value entered from the user. I wouldn't expect the user to enter a CustomerID in CustomerOrderNbr.

EDIT: changed SOOrder.CustomerID by Customer.AcctCD

namespace PX.Objects.SO
{
    public class SOOrderEntry_Extension:PXGraphExtension<SOOrderEntry>
    {
        public const string ordernbrErrorMessage = "Customer name and customer number cannot be same.";

        public void SOOrder_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        { 
            if (!ValidateCustomerID(sender, e.Row as SOOrder))
            {
                PXUIFieldAttribute.SetError<SOOrder.customerID>(sender, e.Row, ordernbrErrorMessage);
            }
        }

        public bool ValidateCustomerID(PXCache sender, SOOrder soOrder)
        {
            if (soOrder != null)
            {
                string soCustomerID = PXSelectorAttribute.GetField(sender, soOrder, typeof(SOOrder.customerID).Name, soOrder.CustomerID, typeof(Customer.acctCD).Name) as string;                   string soCustomerOrderNbr = soOrder.CustomerOrderNbr; 

                if (soCustomerID != null && soCustomerOrderNbr != null)
                {
                    return !soCustomerID.Trim().Equals(soCustomerOrderNbr.Trim(), StringComparison.OrdinalIgnoreCase);
                }
            }             

            return true;
        }
    }
}