微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Acuamtica 升级后通过客户中断事件处理程序更新位置上的自定义字段

如何解决在 Acuamtica 升级后通过客户中断事件处理程序更新位置上的自定义字段

我在 Location DAC 上有一个自定义字段,该字段通过客户屏幕上的事件处理程序进行更新。同样,此自定义字段也可以通过企业帐户屏幕上的事件进行更新。我的代码在 Acumatica 2019 R1 版中工作。但是在 2020 R2 版本中,代码中断了,我无法弄清楚如何相应地对其进行调整。

场景是我们在 Location 上有一个名为 usrResidentialValidated 的布尔值,它指示位置地址是否已通过 FedEx 验证(然后我们有代码可以根据需要使用 FedEx 验证)。如果客户或企业帐户屏幕上的位置信息发生更改,我们需要将相应位置的 usrResidentialValided 设置为 False,以便它可以排队等待后续验证。

正如我所提到的,我们的代码在 Acumatica 2019 R1 中可以运行,但在 2020 R2 中损坏,我看不出如何使其在 2020 R2 中运行。有几件事可能是因素: 1. 2020 R2 Developer Release Notes 的第 44 页指示在升级中客户图上的 LocationExtAddress 视图已移至 DefLocationExt。然而,DefLocationExt 不是一个普通的视图,我不清楚如何在我的情况下使用这个新视图。 2. 此外,CustomerMaint 图现在使用 PX.Objects.CR.Standalone.Location,但我的自定义字段扩展了 PX.Objects.CR.Location。我想知道这是否是另一个麻烦的来源。如果是这样,我也不知道如何最好地处理它。自定义字段目前正在我们的 Acuamtica 实时版本中使用,我需要保留该数据。

这是我的代码

自定义字段以扩展 PX.Objects.CR.Location

using PX.Objects.so;
using PX.Objects.TX;
using PX.Objects;
using System.Collections.Generic;
using System;

namespace PX.Objects.CR
{
  public class LocationExt : PXCacheExtension<PX.Objects.CR.Location>
  {
          
    #region UsrResidentialValidated
    [PXDBBool]
    [PXUIField(displayName="Residential Validated")]
    [PXDefault(false,PersistingCheck = PXPersistingCheck.nothing)]

    public virtual bool? UsrResidentialValidated { get; set; }
    public abstract class usrResidentialValidated : IBqlField { }
    #endregion

  }
}

这是我在客户图扩展上的代码,其中包含事件处理程序(请参阅代码中的注释,了解在 2019 R1 中工作的代码以及我在 2020 R2 中尝试无效的代码):

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using PX.Common;
using PX.Data;
using PX.Objects.CA;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CR.Extensions;
using PX.Objects.CS;
using PX.Objects.so;
using PX.SM;
using PX.Objects.AR.CCPaymentProcessing;
using PX.Objects.Common;
using CashAccountAttribute = PX.Objects.GL.CashAccountAttribute;
using PX.Objects;
using PX.Objects.AR;
using LaSalle;
using LaSalleJO;
using CRLocation = PX.Objects.CR.Standalone.Location;

namespace PX.Objects.AR
{
  
  public class CustomerMaint_Extension:PXGraphExtension<CustomerMaint>
  {
        //  If any fields of the location change,mark location as needing FedEx validation again.
             
        /* ------------ THIS CODE WORKS IN 2019R1 BUT BREAKS IN 2020R2 ----------------- */
        protected virtual void LocationExtAddress_RowUpdated(PXCache sender,PXRowUpdatedEventArgs e)
        {

            if (e.Row == null) return;
            LocationExtAddress row = (LocationExtAddress)e.Row;
            Location location = PXSelect<Location,Where<Location.locationID,Equal < required < Location.locationID >>>>.Select(Base,row.LocationID);

            if (location != null)
            {
                LocationExt locationExt = location.GetExtension<LocationExt>();
                
                if (locationExt != null)
                {
                    locationExt.UsrResidentialValidated = false;
                    PXCache cache = Base.Caches[typeof(Location)];
                    cache.Update(location);
                }
            }
        }
        
         /* ------------ MY ATTEMPT TO GET THE CODE TO WORK IN 2020R2 ----------------- */
         /* This is my attempt to get the LocationExtAddress_RowUpdated event handler to work in 2020R2
            Currently this is partially working. 
                - The event handler is successfully triggered when a Location field changes (e.g. when the Ship Via field on the Shipping tab of Customers is edited)
                - The code does successfully update the cache if I view it in Debug mode
                - The change is saved to the DB with the Persist but that understandably generates an "another process has updated ..." error when you save the Customer record 
                 (without Persist the field is not updated)
                - I wonder if the problem has to do with the fact that my custom field extends PX.Objects.CR.Location not PX.Objects.CR.Standalone.Location
         */
        protected void Location_RowUpdated(PXCache cache,PXRowUpdatedEventArgs e)
        {
            if (e.Row == null) return;
            var row = (CRLocation)e.Row;

            Location location = PXSelect<Location,Equal<required<Location.locationID>>>>.Select(Base,row.LocationID);

            if (location != null)
            {
                LocationExt locationExt = location.GetExtension<LocationExt>();

                if (locationExt != null)
                {    
                    locationExt.UsrResidentialValidated = false;
                    PXCache locCache = Base.Caches[typeof(Location)];
                    locCache.Update(location); 
                    locCache.Persist(location,PXDBOperation.Update); // With this line,it correctly updates the location in the db but then I get an error on the Customer saying my changes will be lost

                    /* -------------------- SOME OTHER ATTEMPTS --------------------- */
                    //defLocationExt.DefLocation.Cache.Update(location); - no error but doesn't save to the db

                    // Doesn't save to the DB
                    //Base.Caches[typeof(Location)].SetValueExt<LocationExt.usrResidentialValidated>(location,false);
                    //Base.Caches[typeof(Location)].Update(locationExt);

                    // Base.Caches[typeof(Location)].MarkUpdated(location); -- doesn't work

                    // This works too but also has the problem of not saving to the DB either
                    //Base.BaseLocations.Cache.RaiseFieldUpdated<LocationExt.usrResidentialValidated>(locationExt,true);
                    //Base.BaseLocations.Cache.Update(location);
                }
            }

        }

        // If address changes,check to see if there's a linked location. If there is,kick off location updated event handler (LocationExtAddress_RowUpdated),// which will mark that FedEx needs validation again 
        
         /* ------------ THIS CODE WORKS IN 2019R1 BUT BREAKS IN 2020R2 ----------------- */
        protected virtual void Address_RowUpdated(PXCache sender,PXRowUpdatedEventArgs e)
         {
             if (e.Row == null) return;
             Address row = (Address)e.Row;

             foreach (LocationExtAddress location in Base.Locations.Select())
             {
                 if (location.DefAddressID == row.AddressID)
                 {
                     Base.Locations.Cache.Update(location); // trigger location updating (for the sake of checking FedEx)
                 }
             }
         }  
  }
}

这是我扩展 BAccount 图的代码

using PX.Objects.CR.Massprocess;
using PX.TM;
using PX.Objects.EP;


using System;
using System.Collections;
using Avalara.AvaTax.Adapter.AvaCert2Service;
using PX.Common;
using PX.Data;
using PX.Data.EP;
using PX.Objects.AR;
using PX.Objects.AP;
using PX.Objects.CM;
using PX.Objects.CS;
using PX.Objects.CT;
using PX.Objects.so;
using PX.SM;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using PX.Objects;
using PX.Objects.CR;
using LaSalleAB;
using LaSalleJO;
using CRLocation = PX.Objects.CR.Standalone.Location;

namespace LaSalle
{
  
  public class BusinessAccountMaint_Extension:PXGraphExtension<BusinessAccountMaint>
  {
        // If Address changes and the address is being used by a location (Same as Main is checked on the location or the location is linked to the Delivery Settings address),mark that the location needs FedEx validation again
        // This works for both the main address and the delivery settings address
        
        
         /* ------------ THIS CODE WORKS IN 2019R1 BUT BREAKS IN 2020R2 ----------------- */
          public virtual void Address_RowUpdating(PXCache sender,PXRowUpdatingEventArgs e)
        {
            if (e.Row == null) return;
            Address row = (Address)e.Row;

            foreach (Location loc in Base.Locations.Select())
            {
                if (loc.DefAddressID == row.AddressID)
                {
                    Location location = PXSelect<Location,loc.LocationID);

                    PX.Objects.CR.LocationExt locationExt = location.GetExtension<PX.Objects.CR.LocationExt>();
                    locationExt.UsrResidentialValidated = false;
                    Base.Caches[typeof(Location)].MarkUpdated(location);
                }
            }

        }*/
        
        
        // If the delivery settings carrier changes,mark FedEx as needing validation again on the associated location (only necessary if the carrier changed to FEDH or FEB)

        /* ------------ THIS CODE WORKS IN 2019R1 BUT BREAKS IN 2020R2 ----------------- */
        public virtual void Location_CCarrierID_FieldUpdating(PXCache sender,PXFieldUpdatingEventArgs e)
        {
            if (e.Row == null) return;
            Location location = (Location)e.Row;

            String carrier = e.NewValue as String;
            if (carrier == "FEDB" || carrier == "FEDH") {

                PX.Objects.CR.LocationExt locationExt = location.GetExtension<PX.Objects.CR.LocationExt>();

                if (locationExt != null && Base.Locations.Current != null)
                {
                    locationExt.UsrResidentialValidated = false;
                    Base.Caches[typeof(Location)].MarkUpdated(location);

                }
            }
        }
              
              
        // If residential flag changes,mark FedEx has needing validation again on the associated location
        
         /* ------------ THIS CODE WORKS IN 2019R1 BUT BREAKS IN 2020R2 ----------------- */
        public virtual void Location_CResedential_FieldUpdating(PXCache sender,PXFieldUpdatingEventArgs e)
        {

            if (e.Row == null) return;
            Location location = (Location)e.Row;

            PX.Objects.CR.LocationExt locationExt = location.GetExtension<PX.Objects.CR.LocationExt>();

            if (locationExt != null && Base.Locations.Current != null)
            {  
                locationExt.UsrResidentialValidated = false;
                Base.Caches[typeof(Location)].MarkUpdated(location);
            }
        }
  }
}

任何帮助将不胜感激。


编辑:根据要求,以下是自定义字段 usrResidentialValidated 在客户位置屏幕上的使用位置的屏幕截图。注意:它仅显示在客户位置上,而不显示在客户上。

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。