问题
I need to create a Contact lookup in SO screen (SO301000). I have already created user defined custom field as below. I is listing all contacts but it is not refreshing based on when select customer. Do I have to write any event for CustomerID to refresh these Contact lookup? Does anyone has any idea?
[PXDBInt]
[PXUIField(DisplayName = "Contact")]
[PXSelector(typeof(Search2<Contact.contactID,
LeftJoin<BAccount, On<BAccount.bAccountID, Equal<Contact.bAccountID>>>>),
DescriptionField = typeof(Contact.displayName), Filterable = true, DirtyRead = true)]
[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 { }
回答1:
You are missing Where Clause and you need to use BAccount2
instead of BAccount
. SOOrderEntry
Graph has data view defined with Vendor
DAC which gets initialized first/before BAccount
and framework will substitute it with Vendor
DAC. To prevent this, you need to use BAccount2
DAC in your BQL.
using System;
using PX.Data;
using PX.Objects.SO;
using PX.Objects.CR;
namespace DemoPkg
{
public class SOOrderPXExt : PXCacheExtension<SOOrder>
{
#region UsrContactID
public abstract class usrContactID : IBqlField { }
[PXDBInt()]
[PXUIField(DisplayName = "Contact", Visibility = PXUIVisibility.Visible)]
[PXSelector(typeof(Search2<Contact.contactID,
LeftJoin<BAccount2, On<BAccount2.bAccountID, Equal<Contact.bAccountID>>>>),
DescriptionField = typeof(Contact.displayName), Filterable = true, DirtyRead = true)]
[PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXFormula(typeof(Default<CRCase.customerID>))]
[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(Where<Contact.isActive, Equal<True>>), PX.Objects.CR.Messages.ContactInactive,
typeof(Contact.displayName))]
public virtual Int32? UsrContactID { get; set; }
#endregion
}
}
And make sure you have AutoRefresh
set to true
in aspx for PXSelector control of this field.
回答2:
I see you do not have a where condition in your selector to be based on the given customer. Try updating your selector to match something like this...
[PXSelector(typeof(Search2<Contact.contactID,
LeftJoin<BAccount, On<BAccount.bAccountID, Equal<Contact.bAccountID>>>,
Where<BAccount.bAccountID, Equal<Current<SOOrder.customerID>>>>),
DescriptionField = typeof(Contact.displayName), Filterable = true, DirtyRead = true)]
In your page also make sure your selector has AutoRefresh="true"
Example:
<px:PXSelector ID="edWeightUOM" runat="server"
DataField="WeightUOM" Size="S" AutoRefresh="true" />
来源:https://stackoverflow.com/questions/42228334/contact-lookup-based-on-customer-selection