Skip to main content
Answer

how to avoid getting duplicated sales orders into my custom screen?

  • May 1, 2023
  • 1 reply
  • 168 views

Forum|alt.badge.img

Hi,

I have customized a new screen. To my screen I’m getting data from soorder DAC and soline DAC. This time, I need to get sales orders without duplicating from the view to my custom screen. When new row is inserted into my line level, I need to update TotalDiscount field of header level with soorder.curydisctot value which is taken from the soorder screen header level. To accomplish avoid duplicating when adding same sales order number , I tried the below code in the row inserted event but it didn’t work.

protected void APProformaItemList_RowInserted(PXCache cache, PXRowInsertedEventArgs e) 
{
var row = (APProformaItemList)e.Row;
APProforma item = APProformas.Current;

//add so discount into form
var distinctSOLines = this.APProformaItems.Select().FirstTableItems.ToList().Select(x => x.Ponbr).Distinct();

foreach(var itemlist in distinctSOLines)
{

SOOrder order= SelectFrom<SOOrder>.Where<SOOrder.orderNbr.IsEqual<SOOrder.orderNbr>>.View.Select(this, itemlist);

item.TotalDiscount = item.TotalDiscount+order.CuryDiscTot;
}
}

APProformaItemList - line level dac

APProforma - header leveldac

ApproformaItems - line level view

ponbr= foreign reference with soline dac

 

Have I done something wrong in this code or is there any other work around to accomplish this? can someone help me with this?

Thank you in advance.

Best answer by Naveen Boga

Hi @oshadarodrigo64  Here are my suggestions.

  1. When you are making a query to SOOrder table, you should pass the Order Type and Order Nbr both as these are the KEY fields. (Order Type is missed in the above query)
  2. Instead of Row_Inserted, Have you tried in the RowUpadated event?
  3. In the above example, you are looping through the items, in this case, multiple items are part of the single Sales Order, so that it will adding up the Discount Amount. To avoid this, you can maintain a LIST, so that if you already added the Discount amount you can ignore the same order next item by adding the condition.

Hope this helps!

1 reply

Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • Answer
  • May 1, 2023

Hi @oshadarodrigo64  Here are my suggestions.

  1. When you are making a query to SOOrder table, you should pass the Order Type and Order Nbr both as these are the KEY fields. (Order Type is missed in the above query)
  2. Instead of Row_Inserted, Have you tried in the RowUpadated event?
  3. In the above example, you are looping through the items, in this case, multiple items are part of the single Sales Order, so that it will adding up the Discount Amount. To avoid this, you can maintain a LIST, so that if you already added the Discount amount you can ignore the same order next item by adding the condition.

Hope this helps!