我在 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();
}
}
这里面有两个问题。
它确实显示了当我选择联系人时填充的电子邮件,但是当我保存时,它会覆盖来自客户的默认电子邮件。
如果我正在创建新的销售订单并选择联系人。如果我错过任何必填字段或任何其他错误(例如 Avalara 错误),则在保存时,它会再次覆盖来自客户的默认值。
请建议。