Solved

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

  • 1 May 2023
  • 1 reply
  • 81 views

Userlevel 3
Badge

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.

icon

Best answer by Naveen Boga 1 May 2023, 20:04

View original

1 reply

Userlevel 7
Badge +17

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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved