-1

I need to create a customer lookup in SO screen (SO301000). I have already created user defined custom field as below.

#region UsrKWBSCustomerID
        [CustomerAndProspect(Filterable = true, DirtyRead = true)]
        [PXUIField(DisplayName = "Customer")]
        //[PXRestrictor(typeof(Where<BAccountR.status, NotEqual<BAccountR.status.inactive>,// Or<BAccountR.type, Equal<BAccountType.customerType>, Or<BAccountR.type, Equal<BAccountType.combinedType>>>,
        //            And<Where<Contact.contactID, Equal<Current<SOOrderExt.usrKWContactID>>,
        //                    Or<Current<SOOrderExt.usrKWContactID>, IsNull>>>>), PX.Objects.CR.Messages.ContactBAccountDiff)]
        //[PXDefault(typeof(Where<BAccountR.status, NotEqual<BAccountR.status.inactive>,// Or<BAccountR.type, Equal<BAccountType.customerType>, Or<BAccountR.type, Equal<BAccountType.combinedType>>>,
        //            And<Where<Contact.contactID, Equal<Current<SOOrderExt.usrKWContactID>>,
        //                    Or<Current<SOOrderExt.usrKWContactID>, IsNull>>>>),PersistingCheck = PXPersistingCheck.Nothing)]
        ////[PXFormula(typeof(Default<Contact.bAccountID>))]
        ////[PXRestrictor(typeof(Where<Contact.isActive, Equal<True>>), PX.Objects.CR.Messages.ContactInactive,
        ////                  typeof(Contact.displayName))]
        //[PXRestrictor(typeof(Where<BAccountR.type, Equal<BAccountType.prospectType>, Or<BAccountR.type, Equal<BAccountType.customerType>, Or<BAccountR.type, Equal<BAccountType.combinedType>>>>), "Business Account is {0}.", new[] { typeof(BAccountR.type) })]
        //[PXSelector(typeof(Search<Customer.bAccountID>), new Type[] { typeof(Customer.acctCD), typeof(Customer.acctName), typeof(Customer.status), typeof(Customer.classID) }, 
        //    SubstituteKey = typeof(Customer.acctName), DescriptionField = typeof(Customer.acctName))]
        public virtual int? UsrKWBSCustomerID { get; set; }
        public abstract class usrKWBSCustomerID : PX.Data.BQL.BqlInt.Field<usrKWBSCustomerID> { }
        #endregion

I also tried below one but did not work v=can some one correct me where i am doing wrong, i expected output is when user selects contact then automatically respective customer should load in my custom field like how Opportunity screen is working

#region UsrKWBSCustomerID
        //[CustomerAndProspect(Filterable = true, DirtyRead = true)]
        [PXDBInt()]
        [PXUIField(DisplayName = "Customer")]
        [PXSelector(typeof(Search2<BAccount2.bAccountID,
                LeftJoin<Contact, On<Contact.bAccountID, Equal<BAccount2.bAccountID>>>, Where<BAccount2.type, Equal<BAccountType.prospectType>, Or<BAccount2.type, Equal<BAccountType.customerType>, Or<BAccount2.type, Equal<BAccountType.combinedType>>>>>),
                DescriptionField = typeof(BAccount2.acctName), Filterable = true, DirtyRead = true)]
        [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
        [PXFormula(typeof(Default<Contact.bAccountID>))]
        [PXRestrictor(typeof(Where2<Where<BAccount2.type, Equal<BAccountType.prospectType>, Or<BAccount2.type, Equal<BAccountType.customerType>, Or<BAccount2.type, Equal<BAccountType.combinedType>>>>,
                    And<Where<Contact.contactID, Equal<Current<SOOrderExt.usrKWContactID>>,
                            Or<Current<SOOrderExt.usrKWContactID>, IsNull>>>>), PX.Objects.CR.Messages.ContactBAccountDiff)]
        [PXRestrictor(typeof(Where<BAccount2.status, Equal<BAccount2.status.inactive>>), "Customer '{0}' is inactive",
                          typeof(BAccount2.acctName))]
 public virtual int? UsrKWBSCustomerID { get; set; }
        public abstract class usrKWBSCustomerID : PX.Data.BQL.BqlInt.Field<usrKWBSCustomerID> { }
        #endregion
BhavyaSri
  • 150
  • 10

1 Answers1

1

Sales order DAC already has a Customer selector using DAC BAccountR. Creating another selector on the same BAccountR DAC will create a conflict because there can only be a single current DAC object.

BAccountR DAC is an alias which inherits from BAccount to prevent this conflict.

You should also create an alias DAC on BAccount. You can copy BAccountR class, rename it (BAccountR2 in example below) and include it in your solution.

[System.SerializableAttribute()]
public partial class BAccountR2 : BAccount
{
    #region BAccountID
    public new abstract class bAccountID : PX.Data.BQL.BqlInt.Field<bAccountID> { }
    #endregion
    #region AcctCD
    public new abstract class acctCD : PX.Data.BQL.BqlString.Field<acctCD> { }
    [PXDimensionSelector("BIZACCT",
        typeof(Search2<BAccountR2.acctCD,
                LeftJoin<Contact, On<Contact.bAccountID, Equal<BAccountR2.bAccountID>, And<Contact.contactID, Equal<BAccountR2.defContactID>>>,
                LeftJoin<Address, On<Address.bAccountID, Equal<BAccountR2.bAccountID>, And<Address.addressID, Equal<BAccountR2.defAddressID>>>>>,
            Where2<Where<BAccountR2.type, Equal<BAccountType.customerType>,
                Or<BAccountR2.type, Equal<BAccountType.prospectType>,
                Or<BAccountR2.type, Equal<BAccountType.combinedType>,
                Or<BAccountR2.type, Equal<BAccountType.vendorType>>>>>,
                And<Match<Current<AccessInfo.userName>>>>>),
        typeof(BAccountR2.acctCD),
        typeof(BAccountR2.acctCD), typeof(BAccountR2.acctName), typeof(BAccountR2.type), typeof(BAccountR2.classID), typeof(BAccountR2.status), typeof(Contact.phone1), typeof(Address.city), typeof(Address.countryID), typeof(Contact.eMail),
        DescriptionField = typeof(BAccountR2.acctName))]
    [PXDBString(30, IsUnicode = true, IsKey = true, InputMask = "")]
    [PXDefault]
    [PXUIField(DisplayName = "Account ID", Visibility = PXUIVisibility.SelectorVisible)]
    [PXFieldDescription]
    public override String AcctCD
    {
        get
        {
            return this._AcctCD;
        }
        set
        {
            this._AcctCD = value;
        }
    }
    #endregion
    #region AcctName
    public new abstract class acctName : PX.Data.BQL.BqlString.Field<acctName> { }
    #endregion
    #region NoteID
    public new abstract class noteID : PX.Data.BQL.BqlGuid.Field<noteID> { }
    #endregion
    #region DefLocationID
    public new abstract class defLocationID : PX.Data.BQL.BqlInt.Field<defLocationID> { }
    #endregion
    #region Type
    public new abstract class type : PX.Data.BQL.BqlString.Field<type> { }
    #endregion
    #region IsCustomerOrCombined
    public new abstract class isCustomerOrCombined : PX.Data.BQL.BqlBool.Field<isCustomerOrCombined> { }
    #endregion
    #region ParentBAccountID
    public new abstract class parentBAccountID : PX.Data.BQL.BqlInt.Field<parentBAccountID> { }
    #endregion
    #region DefContactID
    public new abstract class defContactID : PX.Data.BQL.BqlInt.Field<defContactID> { }
    [PXDBInt()]
    [PXDBChildIdentity(typeof(Contact.contactID))]
    [PXSelector(typeof(Search<Contact.contactID>))]
    [PXUIField(DisplayName = "Default Contact", Visibility = PXUIVisibility.Invisible)]
    public override Int32? DefContactID
    {
        get
        {
            return base.DefContactID;
        }
        set
        {
            base.DefContactID = value;
        }
    }
    #endregion
    #region DefAddressID
    public new abstract class defAddressID : PX.Data.BQL.BqlInt.Field<defAddressID> { }
    #endregion
    #region ViewInCrm
    public new abstract class viewInCrm : PX.Data.BQL.BqlBool.Field<viewInCrm> { }        
    [PXBool]
    [PXUIField(DisplayName = "View In CRM")]
    public new virtual bool? ViewInCrm
    {
        get
        {
            return this._ViewInCrm;
        }
        set
        {
            this._ViewInCrm = value;
        }
    }
    #endregion

    #region Status
    public new abstract class status : PX.Data.BQL.BqlString.Field<status>
    {
        public class ListAttribute : PXStringListAttribute
        {
            public ListAttribute()
                : base(
                    new string[] { Active, Hold, HoldPayments, Inactive, OneTime, CreditHold },
                    new string[] { Messages.Active, Messages.Hold, Messages.HoldPayments, Messages.Inactive, Messages.OneTime, Messages.CreditHold })
            { }
        }

        public const string Active = "A";
        public const string Hold = "H";
        public const string HoldPayments = "P";
        public const string Inactive = "I";
        public const string OneTime = "T";
        public const string CreditHold = "C";

        public class active : PX.Data.BQL.BqlString.Constant<active>
        {
            public active() : base(Active) {; }
        }
        public class hold : PX.Data.BQL.BqlString.Constant<hold>
        {
            public hold() : base(Hold) {; }
        }
        public class holdPayments : PX.Data.BQL.BqlString.Constant<holdPayments>
        {
            public holdPayments() : base(HoldPayments) {; }
        }
        public class inactive : PX.Data.BQL.BqlString.Constant<inactive>
        {
            public inactive() : base(Inactive) {; }
        }
        public class oneTime : PX.Data.BQL.BqlString.Constant<oneTime>
        {
            public oneTime() : base(OneTime) {; }
        }
        public class creditHold : PX.Data.BQL.BqlString.Constant<creditHold>
        {
            public creditHold() : base(CreditHold) {; }
        }
    }
    #endregion
}

On your selector use the new DAC alias you created. Below is a copy of SOOrder.CustomerID field where I replaced the BAccountR alias to the new BAccountR2 and renamed the field from CustomerID to UsrCustomerID.

public abstract class usrCustomerID : PX.Data.BQL.BqlInt.Field<usrCustomerID> { }

[PXDefault]
[CustomerActive(typeof(Search<BAccountR2.bAccountID, Where<True, Equal<True>>>),
                Visibility = PXUIVisibility.SelectorVisible, 
                DescriptionField = typeof(Customer.acctName), 
                Filterable = true)]
[CustomerOrOrganizationInNoUpdateDocRestrictor]
[PXForeignReference(typeof(Field<SOOrder.usrCustomerID>.IsRelatedTo<BAccount.bAccountID>))]

public virtual Int32? UsrCustomerID { get; set; }
Hugues Beauséjour
  • 8,067
  • 1
  • 9
  • 22