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

修改Acumatica项目CustomerId后未更新客户且触发无效位置错误求助

解决Acumatica项目变更客户时的默认位置报错问题

问题根源

报错核心原因是:修改项目关联的CustomerId时,Acumatica会自动尝试填充客户的默认位置(即报错中的MAIN),但该位置在新旧客户的位置列表中均不存在,触发系统字段验证逻辑;同时Graph上下文未及时刷新,旧客户数据残留加剧了验证冲突。

具体解决方法

  • 手动指定有效客户位置
    不要依赖系统自动填充位置,更新CustomerId前后,主动查询目标客户的有效位置并赋值给CustomerLocationId,确保使用的位置ID存在于目标客户的位置列表中:

    // 查询目标客户的激活位置
    var targetLocations = PXSelect<Location, 
        Where<Location.bAccountID, Equal<Required<Location.bAccountID>>, 
            And<Location.isActive, Equal<True>>>>.Select(graph, newCustomerId);
    
    if (targetLocations.Count > 0)
    {
        var validLocation = targetLocations[0] as Location;
        // 先设置客户ID,再绑定有效位置
        project.CustomerId = newCustomerId;
        project.CustomerLocationId = validLocation.LocationID;
    }
    graph.Project.Update(project);
    
  • 强制刷新Graph上下文
    更新项目后,手动将当前项目实例设置为Graph的Current对象,避免旧客户数据残留:

    graph.Project.Update(project);
    // 刷新上下文,确保Graph指向最新的项目数据
    graph.Project.Current = project;
    // 执行保存操作
    graph.Actions.PressSave();
    
  • 确保目标客户存在激活位置
    如果目标客户没有任何激活的位置,需先创建或激活一个客户位置,再关联项目:

    // 创建目标客户的默认位置
    var newLocation = new Location
    {
        BAccountID = newCustomerId,
        LocationCD = "DEFAULT",
        Descr = "Default Customer Location",
        IsActive = true
    };
    graph.Location.Insert(newLocation);
    graph.Actions.PressSave();
    
    // 再将该位置绑定到项目
    project.CustomerId = newCustomerId;
    project.CustomerLocationId = newLocation.LocationID;
    graph.Project.Update(project);
    
  • 临时跳过自动位置验证(特殊场景)
    如果业务允许不强制关联位置,可通过SetValueExt方法先清空位置、设置客户,再重新绑定有效位置,绕过系统的自动填充逻辑:

    // 先清空现有位置
    graph.Project.SetValueExt<PMProject.customerLocationID>(project, null);
    // 设置新客户ID
    graph.Project.SetValueExt<PMProject.customerID>(project, newCustomerId);
    // 绑定目标客户的有效位置
    graph.Project.SetValueExt<PMProject.customerLocationID>(project, validLocationId);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 19:52:13