You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在ExtendToCustomer流程中更新cTaxZoneID及Location字段?

解决方案:ExtendToCustomer流程中更新CTaxZoneID字段

问题原因分析

你当前的实现存在两个核心问题:

  1. 第一种方法中,直接修改editCustomer.BaseLocations.Current.CTaxZoneID但未正确标记记录为更新状态,且可能未确保BaseLocations视图已加载目标地址记录。
  2. 第二种方法错误使用了原图(Base)的缓存,而跳转后的CustomerMaint是独立的图实例,两者缓存不共享,导致修改无法同步到新图。

正确实现代码

以下是修正后的代码,确保在跳转后的CustomerMaint实例中正确修改并持久化地址字段:

public virtual IEnumerable ExtendToCustomerPXExt(PXAdapter adapter)
{
    try
    {
        var graphExt = Base.GetExtension<ExtendToCustomer>();
        if (graphExt.extendToCustomer.GetEnabled()) 
        {
            graphExt.extendToCustomer.Press();
        }
    }
    catch (PXRedirectRequiredException ex)
    {
        if (ex.Graph is CustomerMaint editCustomer)
        {
            // 设置客户类别
            BAccount customer = editCustomer.BAccount.Current;
            customer.CustomerClassID = "FAMA";
            editCustomer.BAccount.Update(customer);
            editCustomer.BAccount.View.Answer = WebDialogResult.Yes;

            // 处理默认地址的CTaxZoneID更新
            if (customer?.DefLocationID != null)
            {
                // 从CustomerMaint的BaseLocations视图获取目标地址
                Location targetLocation = editCustomer.BaseLocations.SelectSingle(customer.DefLocationID);
                if (targetLocation != null)
                {
                    targetLocation.CTaxZoneID = "NEWTAXE";
                    // 使用CustomerMaint实例的视图更新方法,自动标记缓存并触发验证
                    editCustomer.BaseLocations.Update(targetLocation);
                }
            }
        }
        // 重新抛出异常以完成跳转流程
        throw;
    }
    return adapter.Get();
}

关键注意事项

  • 使用目标图实例操作:所有修改必须基于跳转后的CustomerMaint实例(editCustomer),而非原图的缓存或视图,两个图实例的缓存完全独立。
  • 显式标记更新:调用editCustomer.BaseLocations.Update(targetLocation)或editCustomer.Caches[typeof(Location)].MarkUpdated(targetLocation),确保记录被标记为待更新状态。
  • 确保记录存在:先校验DefLocationID不为空,再查询目标地址,避免空引用异常。
  • 保留跳转流程:重新抛出PXRedirectRequiredException,否则系统会中断跳转,无法打开客户维护页面。

内容的提问来源于stack exchange,提问作者Xavier LARTEM

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 15:14:56