Skip to main content

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.

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!


Reply