Skip to main content
Answer

block duplicate Customer Order Nbr just for the "SO" order type

  • May 3, 2023
  • 6 replies
  • 122 views

i have code to block duplicate Customer Order Nbr, but i want it should be filtered just for the “SO” Order Type.

how can i do that? 

 

  [PXCheckUnique(Where = typeof(Where2<Where<SOOrder.orderType, Equal<Current<SOOrder.orderType>>,
        And<SOOrder.customerOrderNbr, Equal<Current<SOOrder.customerOrderNbr>>,
            And<SOOrder.customerID, Equal<Current<SOOrder.customerID>>>>>, 
        And<SOOrder.status, NotEqual<SOOrderStatus.cancelled>>>),
        ErrorMessage = "Order already exists with this Customer Order Nbr and Customer ID ")]

Best answer by darylbowman

You could put the constant SOOrderTypeConstants.salesOrder in the BQL statement, but without knowing the situation, I can’t recommend that it would be a good idea.

 

[PXCheckUnique(Where = typeof(
Where2<
Where<SOOrder.orderType, Equal<SOOrderTypeConstants.salesOrder>,
And<SOOrder.customerOrderNbr, Equal<Current<SOOrder.customerOrderNbr>>,
And<SOOrder.customerID, Equal<Current<SOOrder.customerID>>>>>,
And<SOOrder.status, NotEqual<SOOrderStatus.cancelled>>>
), ErrorMessage = "An 'SO' Order already exists with this Customer Order Nbr and Customer ID ")]

 

6 replies

Manikanta Dhulipudi
Captain II
Forum|alt.badge.img+15

Hi @yoelb 

Can you use customer order Nbr validation on  order types,


  • Author
  • Freshman II
  • May 3, 2023

Hi @manikantad18 ,

 

to use the built in validation it needs to be checked “Require Customer Order Nbr”, and it will not allow to be empty, which will not work for us

 


Dioris Aguilar
Jr Varsity I
Forum|alt.badge.img+2

@yoelb Try adding a fieldUpdated event for CustomerOrderNbr, do the search and raise an error if another order has the same customer order:
 

public void SOOrder_CustomerOrderNbr_FieldUpdated(...){
if(e.Row == null) return;
if(PXSelect<SOOrder, Where<SOOrder.customerOrderNbr, Equal<Required<SOOrder.customerOrderNbr>>,
And<SOOrder.orderType, NotEqual<Required<SOOrder.orderType>>,
And<SOOrder.orderNbr, NotEqual<Required<SOOrder.orderNbr>>>>>>
.Select(Base, e.Row.CustomerOrderNbr, e.Row.OrderType, e.Row.OrderNbr)
.Count() > 0)
{
throw new PXException("Another order has same customer order...");
}
}

Probably you would need to implement this same validation in RowPersisting event to make it more robust.


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

You could put the constant SOOrderTypeConstants.salesOrder in the BQL statement, but without knowing the situation, I can’t recommend that it would be a good idea.

 

[PXCheckUnique(Where = typeof(
Where2<
Where<SOOrder.orderType, Equal<SOOrderTypeConstants.salesOrder>,
And<SOOrder.customerOrderNbr, Equal<Current<SOOrder.customerOrderNbr>>,
And<SOOrder.customerID, Equal<Current<SOOrder.customerID>>>>>,
And<SOOrder.status, NotEqual<SOOrderStatus.cancelled>>>
), ErrorMessage = "An 'SO' Order already exists with this Customer Order Nbr and Customer ID ")]

 


  • Author
  • Freshman II
  • May 3, 2023

@darylbowman  -  Thank you


AndrewBGL
Pro I
Forum|alt.badge.img
  • Pro I
  • July 19, 2023

Hello,

Here is the Screen ID in 23R1 to change the Customer Order Nbr. Validation.

Order Types (SO201000)