Partnumber should not be the same for all the order entry

Dear All ,
I need to put the validation as , Partnumber should not be the same for all the sales order lines .

Any one can help me out to write codes, I tried to bring the results by grouping option by orderNum but that didn’t work.

Can there be duplicates or not a second line of the same? Or is it at some point in time you want to check if ALL of the PartNums are the same?

1 Like

Thanks for your reply ,

Second line Partnum should not be the same as first line / previous line PartNum.

Let say ,
If first Part , PartNum is ABC then second part should not be the same . If user add second line PartNum as ABC then system should validate .

Do your trace to see what methods are called and I think SalesOrder.ChangePartNumMaster will be in the list. In there or a call before you can check for the PartNum to already exist and thrown an exception.

you can create a BPM that does a COUNT on the sales order for the part number on the current line.if you look for all line items (except the line you are on) and find one or more in the count, then you can reject the current line change.

1 Like

Thanks , @timshuwy , it would be great if you can share custom code too.

I used this code , but not working

/* TO DO: replace object variables with typed variables. Add reference if necessary.*/
object THROW_PRIVATE = null;
String PartNum = "";
Erp.Tables.OrderDtl OrderDtl;
var ttOrderDtl_xRow = (from ttOrderDtl_Row in ttOrderDtl
where string.Equals(ttOrderDtl_Row.RowMod, IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase)
select ttOrderDtl_Row).FirstOrDefault();
if (ttOrderDtl_xRow != null)
{
OrderDtl = (from OrderDtl_Row in Db.OrderDtl
where (string.Compare(OrderDtl_Row.Company, ttOrderDtl_xRow.Company, true) == 0) && (OrderDtl_Row.OrderNum == ttOrderDtl_xRow.OrderNum) && (string.Compare(OrderDtl_Row.PartNum, ttOrderDtl_xRow.PartNum, true) == 0) && (OrderDtl_Row.OrderNum == ttOrderDtl_xRow.OrderNum)
select OrderDtl_Row).FirstOrDefault();
if (OrderDtl != null)
{
PartNum = OrderDtl.PartNum;
CallContext.Current.ExceptionManager.AddBLException("Existing PartNum Used ");
THROW_PRIVATE = null;
}
}

Try this:
This is at OrderDtl- Data Directive-In-Trans

int AddedLine;
int PreviousLine;
var AddedLineRecord = (from X in ttOrderDtl where X.RowMod == "A" && X.Company == Session.CompanyID select X).FirstOrDefault();
if(AddedLineRecord != null)
{
  AddedLine = AddedLineRecord.OrderLine;
    if(AddedLine != 1)
    {
        PreviousLine = AddedLine - 1;
          if(PreviousLine != 0 && PreviousLine > 0)
              {
                      var PreviousLineRecord = (from Y in Db.OrderDtl
                      where Y.Company == AddedLineRecord.Company &&
                      Y.OrderNum == AddedLineRecord.OrderNum &&
                      Y.OrderLine == PreviousLine
                      select Y).FirstOrDefault();
                          if(PreviousLineRecord != null && PreviousLineRecord.PartNum == AddedLineRecord.PartNum)
                              {                            CallContext.Current.ExceptionManager.AddBLException($"Newly Added line {AddedLine} has same PN as Previous Line {PreviousLine}");
                               }
                }
      }
}

Thanks …