0

我在 SOOrder 摘要上创建了一个自定义联系人字段,以便用户可以根据所选客户选择客户联系人。

这是 SOOrder Extension 上的自定义联系人字段定义-

[PXDBInt]
[PXUIField(DisplayName = "Contact", Visibility = PXUIVisibility.Visible)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXSelector(typeof(Search2<Contact.contactID,
	LeftJoin<BAccount2, On<BAccount2.bAccountID, Equal<Contact.bAccountID>>>,
	Where<Contact.contactType, Equal<ContactTypesAttribute.person>,
							Or<Contact.contactType, Equal<ContactTypesAttribute.lead>>>>),
	DescriptionField = typeof(Contact.displayName), Filterable = true)]
[PXRestrictor(typeof(Where<Contact.contactType, NotEqual<ContactTypesAttribute.bAccountProperty>,
		And<Where<BAccount2.bAccountID, Equal<Current<SOOrder.customerID>>,
				Or<Current<SOOrder.customerID>, IsNull>>>>), PX.Objects.CR.Messages.ContactBAccountDiff)]
[PXRestrictor(typeof(Where2<Where2<
				 Where<Contact.contactType, Equal<ContactTypesAttribute.person>,
						Or<Contact.contactType, Equal<ContactTypesAttribute.lead>>>,
					And<
						Where<BAccount2.type, IsNull,
							Or<BAccount2.type, Equal<BAccountType.customerType>,
								Or<BAccount2.type, Equal<BAccountType.prospectType>,
								Or<BAccount2.type, Equal<BAccountType.combinedType>>>>>>>,
		And<WhereEqualNotNull<BAccount2.bAccountID, SOOrder.customerID>>>), "Contact '{0}' ({1}) has sales order for another business account.", typeof(Contact.displayName), typeof(Contact.contactID))]
[PXRestrictor(typeof(Where<Contact.isActive, Equal<True>>), PX.Objects.CR.Messages.ContactInactive, typeof(Contact.displayName))]
[PXDBChildIdentity(typeof(Contact.contactID))]
public virtual int? UsrCustContactID { get; set; }
public abstract class usrCustContactID : IBqlField { }

现在,每当用户选择任何联系人时,我都会在 SOOrder 屏幕的发货设置选项卡上使用自定义联系人字段中所选联系人的电子邮件覆盖电子邮件。我已经为它编写了下面的代码,但似乎它不起作用。

protected virtual void SOOrder_UsrCustContactID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
{
	SOOrderEntry graph = PXGraph.CreateInstance<SOOrderEntry>();

	SOOrderExtension ext = PXCache<SOOrder>.GetExtension<SOOrderExtension>(Base.Document.Current);

	Contact custContact = PXSelect<Contact,
		Where<Contact.contactID, Equal<Required<Contact.contactID>>>>.Select(graph, ext.UsrCustContactID);

	if (custContact != null && !string.IsNullOrEmpty(custContact.EMail))
	{
		graph.Document.Current = Base.Document.Current;

		Base.Shipping_Contact.Current.OverrideContact = true;
		Base.Shipping_Contact.Current.Email = custContact.EMail;

		graph.Shipping_Contact.Current = Base.Shipping_Contact.Current;

		graph.Shipping_Contact.Current.OverrideContact = true;
		graph.Shipping_Contact.Current.Email = custContact.EMail;

		Base.Shipping_Contact.Update(graph.Shipping_Contact.Current);
		
		graph.Actions.PressSave();
	}
}

这里面有两个问题。

  1. 它确实显示了当我选择联系人时填充的电子邮件,但是当我保存时,它会覆盖来自客户的默认电子邮件。

  2. 如果我正在创建新的销售订单并选择联系人。如果我错过任何必填字段或任何其他错误(例如 Avalara 错误),则在保存时,它会再次覆盖来自客户的默认值。

请建议。

4

1 回答 1

3

要将客户联系电子邮件复制到送货地址电子邮件字段中,您的SOOrder_UsrCustContactID_FieldUpdated处理程序应实现如下:

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    protected void SOOrder_UsrCustContactID_FieldUpdated(PXCache sender, PXFieldUpdatedEventArgs e)
    {
        var contact = PXSelectorAttribute.Select<SOOrderExtension.usrCustContactID>(
            sender, e.Row) as Contact;
        if (contact != null)
        {
            var shippingContact = (SOShippingContact)Base.Shipping_Contact.Select();
            shippingContact.OverrideContact = true;
            shippingContact = Base.Shipping_Contact.Update(shippingContact);
            shippingContact = (SOShippingContact)Base.Shipping_Contact.Select();
            shippingContact.Email = contact.EMail;
        }
    }
}

请注意,在将OverrideContact设置为true之后,在Shipping_Contact数据视图上调用了Update方法,然后从Shipping_Contact视图中进行了额外的选择。绝对必须第二次调用Select方法,因为当OverrideContact设置为 true 时,系统会创建一个新的SOShippingContact DAC 实例并将其插入缓存中。从缓存中获取新SOShippingContact实例的最简单方法是通过Shipping_Contact数据视图上的Select方法。

于 2017-10-12T15:48:41.850 回答