0

I have a custom code in SOLine_RowUpdated event, my code works fine and that's all I need, but when I finally get the expected value on SOLine.curyUnitPrice field the base event or base logic changes the value.

I would like to know how can I skip the base event or base logic so that my value doesn't change.

This is my SOOrderEntry_Extension graph:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using PX.Common;
using PX.Data;
using PX.Objects.AP;
using PX.Objects.AR;
using PX.Objects.CA;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.DR;
using PX.Objects.EP;
using PX.Objects.GL;
using PX.Objects.IN;
using PX.Objects.PM;
using PX.Objects.PO;
using PX.Objects.TX;
using POLine = PX.Objects.PO.POLine;
using POOrder = PX.Objects.PO.POOrder;
using System.Threading.Tasks;
using PX.CarrierService;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects.AR.CCPaymentProcessing;
using PX.Objects.AR.CCPaymentProcessing.Common;
using PX.Objects.AR.CCPaymentProcessing.Helpers;
using PX.Objects.AR.CCPaymentProcessing.Interfaces;
using ARRegisterAlias = PX.Objects.AR.Standalone.ARRegisterAlias;
using PX.Objects.AR.MigrationMode;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects.Common.Extensions;
using PX.Objects.IN.Overrides.INDocumentRelease;
using PX.CS.Contracts.Interfaces;
using Message = PX.CarrierService.Message;
using PX.TaxProvider;
using PX.Data.DependencyInjection;
using PX.LicensePolicy;
using PX.Objects.Extensions.PaymentTransaction;
using PX.Objects.SO.GraphExtensions.CarrierRates;
using PX.Objects.Common.Bql;
using PX.Objects;
using PX.Objects.SO;

namespace PX.Objects.SO
{
  public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
  {
    #region Event Handlers

    protected void SOLine_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e)
    {
        SOLine row = (SOLine)e.Row;

        if (row == null)
        {
            return;
        }

        if (row.SubItemID == null) 
        {
            row.CuryUnitPrice = (decimal?) 0.01;
            return;
        }

        if (row.SubItemID != null)
        {
            if (row.SiteID == null)
            {
                row.CuryUnitPrice = (decimal?) 0.01;
                return;
            }
            
            if (row.OrderQty > 0)
            {
                    return;
            }
            else 
            {
                    string cadena = "MAIN";
                    Location location = PXSelect<Location,
                                                Where<Location.bAccountID, Equal<Required<Location.bAccountID>>,
                                                  And<Location.locationCD, Equal<Required<Location.locationCD>>>
                                                >>.Select(Base, row.CustomerID, cadena);


                  ARSalesPrice salesprice = PXSelect<ARSalesPrice,
                                                    Where<ARSalesPrice.custPriceClassID, Equal<Required<ARSalesPrice.custPriceClassID>>,
                                                        And<ARSalesPrice.inventoryID, Equal<Required<ARSalesPrice.inventoryID>>, 
                                                        And<ARSalesPriceExt.usrSubItemID, Equal<Required<ARSalesPriceExt.usrSubItemID>>,
                                                            And<ARSalesPrice.breakQty, LessEqual<Required<ARSalesPrice.breakQty>>
                                                            >
                                                          >
                                                       >
                                                    >,
                                                    OrderBy<Desc<ARSalesPrice.breakQty>>
                                                >.Select(Base, location.CPriceClassID, row.InventoryID, row.SubItemID, row.Qty);
    
                  if(salesprice == null)
                  {
                      ARSalesPrice salesprice2 = PXSelect<ARSalesPrice,
                                                          Where<ARSalesPrice.custPriceClassID, Equal<Required<ARSalesPrice.custPriceClassID>>,
                                                              And<ARSalesPrice.inventoryID, Equal<Required<ARSalesPrice.inventoryID>>,
                                                              And<ARSalesPriceExt.usrSubItemID, Equal<Required<ARSalesPriceExt.usrSubItemID>>
                                                              >
                                                            >
                                                          >,
                                                          OrderBy<Asc<ARSalesPrice.breakQty>>
                                                      >.Select(Base, location.CPriceClassID, row.InventoryID, row.SubItemID);
                    
                      if (salesprice2 != null)
                      {
                          cache.SetValue<SOLine.curyUnitPrice>(row, salesprice2.SalesPrice);
                      }
                      else
                      {
                          row.CuryUnitPrice = (decimal?) 0.01;
                      }  
                  }
                  else
                  {
                      cache.SetValue<SOLine.curyUnitPrice>(row, salesprice.SalesPrice);
                  }
            }
        }
    }
    #endregion
  }
}

Can you help me with this?

1 Answers1

0

You added an event rather than overriding it. You need to specify the appropriate delegate when overriding a base event. Then you can invoke that base event or in your case, not.

using PX.Data;

namespace PX.Objects.SO
{
    public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
    {
        #region Event Handlers

        protected void SOLine_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated baseEvent)
        {
            baseEvent.Invoke(cache, e);  //  <- comment out to prevent calling the base event

            // Insert my custom code here
        }
        #endregion
    }
}
Brian Stevens
  • 1,826
  • 1
  • 7
  • 16
  • Hello, I already did that but I still have the same issue, I did not call the base event. @BrianStevens – Alejandro Alvarado Oct 19 '20 at 22:04
  • What you posted does NOT utilize PXRowUpdated as a delegate. Without specifying the PXRowUpdated delegate, you aren't overriding the base event, so it will always fire. You need to include the delegate to turn your event handler into an override. – Brian Stevens Oct 19 '20 at 22:06
  • Maybe I didn't explain myself, I followed your recommendation after you answered, but I still have the same issue. Currently this is a part of my code: `protected void SOLine_RowUpdated(PXCache cache, PXRowUpdatedEventArgs e, PXRowUpdated InvokeBaseHandler) { /*if(InvokeBaseHandler != null) InvokeBaseHandler(cache, e);*/ var row = (SOLine)e.Row; if (row == null) { return; } <- more code below` @BrianStevens – Alejandro Alvarado Oct 20 '20 at 00:11
  • Gotcha. With the line commented out as you have it in the comment, the base should not fire. Can you explain what you are seeing that appears the base is firing? Also, are you sure that your graph extension has been published to the project? My sysadmin updated files in my customization project (from production) before publishing last week, so he lost my DLL in the project. You could confirm by using PXTrace.WriteInformation("you are here"); in your event handler to make sure that your overrride is actually firing. – Brian Stevens Oct 20 '20 at 00:52
  • I think I know what the issue is, SOLine_RowSelected event handler is firing and therefore it is executing the base event, I will try to override it too. @BrianStevens – Alejandro Alvarado Oct 20 '20 at 02:16
  • Yes, that event handler would fire as well. Since I don't know what you are trying to do, all I can advise is just make sure you override the same way. However, as I'm sure you know, failure to fire these base events can cause serious data integrity issues. Be sure that any base event you disable handles the important points in your override event handler. RowSelected tends to control access to fields and CRUD functions on that DAC. Also, sometimes what you expect to happen in a RowSelected actually happens in an Automation Step. – Brian Stevens Oct 20 '20 at 02:44
  • 1
    After a deep investigation, I found the event handler that was changing the value of the CuryUnitPrice field, that event is called "SOLine_OrderQty_FieldUpdated", I was able to override this event and put the appropriate customization and everything worked fine. Thanks for your recommendations. @BrianStevens – Alejandro Alvarado Oct 20 '20 at 14:17