Skip to main content
Answer

Sales Order Line: Update UnitPrice with UnitCost

  • April 28, 2025
  • 2 replies
  • 92 views

We’re running 2023R2 and I’m trying to update the UnitPrice to equal the UnitCost when entering items in a “No Charge” Sales Order.  Using the following code:

namespace PX.Objects.SO
{
  public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
  {
     // Update prices when order quantities updated
    protected void _(Events.FieldUpdated<SOLine.orderQty> e)
  {
    var order = Base.Document.Current;
    var line = e.Row;
    if (order?.CustomerOrderNbr?.Contains("SE") == true && line != null)
    {
        // Use SetValueExt to ensure all business logic and UI updates occur
        e.Cache.SetValueExt<SOLine.curyUnitPrice>(line, line.CuryUnitCost);
    }
  }

    // Update prices when CustomerOrdNbr changes
    protected void _(Events.FieldUpdated<SOOrder.customerOrderNbr> e)
    {
        if (e.NewValue?.ToString().Contains("SE") == true)
        {
            foreach (SOLine line in Base.Transactions.Select())
            {
           if (line.CuryUnitPrice > 0)
          {
                line.CuryUnitPrice = line.UnitCost;
                Base.Transactions.Update(line);
            }
        }
    }
  }
 }
}

I’ve been able to “update” a Sales Order to make it No Charge and have the UnitPrice adjusted properly by updating the CustomerOrderNbr but I haven’t been able to get it to work “in process”.  Our default value for OrderQty is zero, so my thought was to update the UnitPrice when the OrderQty is updated.  Unfortunately, my code won’t compile.  I keep getting this error message:  

\App_RuntimeCode\SOOrderEntry.cs(73): error CS1061: 'object' does not contain a definition for 'CuryUnitCost' and no accessible extension method 'CuryUnitCost' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)

I’m sure it’s something simple that I’m missing.  Anyone have any ideas as to what it might be?

Thanks.

Best answer by Vignesh Ponnusamy

Hi ​@bryckman04,

I didn’t test it, but instead of var line = e.Row; try like below,

SOLine line = (SOLine)e.Row;

Feel free to post if you have any questions.!

2 replies

Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi ​@bryckman04,

I didn’t test it, but instead of var line = e.Row; try like below,

SOLine line = (SOLine)e.Row;

Feel free to post if you have any questions.!


  • Author
  • Freshman I
  • April 28, 2025

That worked perfectly! Compiled, ran, and performed just like I imagined it.  Thank you very much.  I figured that I had defined line improperly and I didn’t know how to fix it.

 

Thanks again.