【问题标题】:Copying Sales Person From one Customer to Another将销售人员从一个客户复制到另一个客户
【发布时间】:2019-10-14 23:57:43
【问题描述】:

当父帐户更新时,我试图将默认销售人员从父帐户复制到当前客户。由于某种原因,销售人员的记录被复制了。因此,我在“计费设置”选项卡上选择了一个父帐户,然后在“销售人员”选项卡上,有两个从父帐户复制的重复销售人员。父帐户上只有一名销售人员。当我保存客户时,当然会出现错误:

“违反主键约束“CustSalesPeople_PK”。无法在对象“dbo.CustSalesPeople”中插入重复键”

我在我的代码中设置了一个断点,以确认它只运行了一次。关于为什么会发生这种情况的任何想法?

TIA!

public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
{

    public PXSelect<CustSalesPeople, Where<CustSalesPeople.bAccountID, 
        Equal<Current<Customer.parentBAccountID>>>> ParentSalesPeople;

    #region Event Handlers
    protected virtual void Customer_ParentBAccountID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
    {
        if (e.Row == null)
            return;

        Customer cust = (Customer)e.Row;

        if ((e.OldValue == null) || ((int?)e.OldValue != cust.ParentBAccountID))
        {

            if (cust.ParentBAccountID > 0)
            {

                foreach (CustSalesPeople salesPerson in ParentSalesPeople.Select())
                {
                    if (salesPerson.IsDefault == true)
                    {
                        CustSalesPeople sp = Base.SalesPersons.Insert();
                        sp.BAccountID = cust.BAccountID;
                        sp.CommisionPct = salesPerson.CommisionPct;
                        sp.IsDefault = true;
                        sp.LocationID = salesPerson.LocationID;
                        sp.SalesPersonID = salesPerson.SalesPersonID;
                        sp = Base.SalesPersons.Update(sp);
                        //sender.PersistUpdated(sp);
                        break;
                    }
                }

            }
        }


    }
   #endregion
  }

【问题讨论】:

    标签: acumatica


    【解决方案1】:

    这里有几样东西我想打。

    首先,如错误消息所述,您可能插入了重复的销售人员记录。我会先检查它是否存在于数据库中。

    这也可能是由于销售人员隶属于客户所在地。您将其附加到父位置的 locationID。您可能希望为客户搜索匹配的 locationCD(例如 MAIN),并在需要时使用该键更新销售人员。

    【讨论】:

    • 感谢您的意见!我已经确认销售人员不在客户的数据库中。它们没有显示在客户屏幕上的销售人员选项卡上。我更新了代码以将 sp.LocationID = salesPerson.LocationID 更改为 sp.LocationID = cust.DefLocationID 但是,我收到“AR 错误:已为所有客户位置添加了此销售人员。”我现在使用的是 19.111.0038 版本。
    猜你喜欢
    • 1970-01-01
    • 2020-04-12
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    相关资源
    最近更新 更多