Skip to main content
Solved

Load data in location field based on selected customer


Forum|alt.badge.img

Hi, 

I have developed a new screen, In this screen I need to load all the locations of related customer as drop down list in the location filed to allow select and add to the field.

To accomplish this, I used PXSelector attribute like below in the DAC but it is not working as expected. 

 

#region LocationID
        [PXDBString(30, IsUnicode = true, InputMask = "")]
        [PXUIField(DisplayName = "Location",Enabled =false)]

        //[PXSelector(typeof(Search<Location.descr, Where<Location.bAccountID, Equal<Current<APProforma.customerID>>>>))]
        [PXSelector(typeof(Search2<Location.descr,InnerJoin<Customer,On<Location.locationCD, Equal<Customer.defLocationID>>>>))]
        public virtual string LocationID { get; set; }
    public abstract class locationID : PX.Data.BQL.BqlString.Field<locationID> { }
    #endregion

 

Can someone help me on this?

thank you.

 

Best answer by Vinay Koppula

@oshadarodrigo64 Since the LocationActive attribute already consist of the PXDBInt, so no need to declare it again. Just use the below code to declare your DAC field. Also, check the code in the .aspx as well. 

#region LocationCD
LocationActive(typeof(Where<Location.bAccountID, Equal<Current<APProforma.customerID>>,
            And<MatchWithBranch<Location.cBranchID>>>), DescriptionField = typeof(Location.descr), Visibility = PXUIVisibility.SelectorVisible)]    
        [PXUIField(DisplayName = "Property")]
        public virtual int? LocationCD { get; set; }
        public abstract class locationCD: PX.Data.BQL.BqlInt.Field<locationCD> { }

#endregion


View original
Did this topic help you find an answer to your question?

Patrick Chen
Varsity I
Forum|alt.badge.img+2

Your code has a typo

[PXSelector(typeof(Search2<Location.descr,InnerJoin<Customer,On<Location.locationCD, Equal<Customer.defLocationID>>>>))]

Should be LocationID


Forum|alt.badge.img

Hi @Patrick Chen ,

Thank you for your response, I changed to LocationID but it doesn’t make sense, is there any other way you suggest to do?

 


Vinay Koppula
Semi-Pro II
Forum|alt.badge.img+1

@oshadarodrigo64 I have reviewed your code, but it does not make any sense.

  1. [PXUIField(DisplayName = "Location",Enabled =false)] - If Enabled: false then how will you select the values from the selector?
  2. DataType of LocationID is set to String, Ideal way is to use int. If you use Int then you can use the LocationActive attribute to filter the records. For reference below is the code that you can see the CustomerLocationID field in ARRegister DAC.
    [LocationActive(typeof(Where<Location.bAccountID, Equal<Optional<ARRegister.customerID>>,            And<MatchWithBranch<Location.cBranchID>>>), DescriptionField = typeof(Location.descr), Visibility = PXUIVisibility.SelectorVisible, TabOrder = 3)]

     


Vinay Koppula
Semi-Pro II
Forum|alt.badge.img+1

@oshadarodrigo64 However, I see that you have comment a code which will filter the desired records, was that not worked for you?


Forum|alt.badge.img+9
  • Semi-Pro III
  • March 23, 2023

Hi @oshadarodrigo64 ,

I have used existing location selector code to accomplish this and it works fine for me.

  • Find below code for selector.
#region UsrLocationField
        public abstract class usrLocationField: PX.Data.BQL.BqlInt.Field<usrLocationField> { }
        protected Int32? UsrLocationField;
        [LocationActive(typeof(Where<Location.bAccountID, Equal<Current<SOOrder.customerID>>,
            And<MatchWithBranch<Location.cBranchID>>>), DescriptionField = typeof(Location.descr), Visibility = PXUIVisibility.SelectorVisible)]
        [PXDefault(typeof(Coalesce<Search2<BAccountR.defLocationID,
            InnerJoin<CRLocation, On<CRLocation.bAccountID, Equal<BAccountR.bAccountID>, And<CRLocation.locationID, Equal<BAccountR.defLocationID>>>>,
            Where<BAccountR.bAccountID, Equal<Current<SOOrder.customerID>>,
                And<CRLocation.isActive, Equal<True>,
                And<MatchWithBranch<CRLocation.cBranchID>>>>>,
            Search<CRLocation.locationID,
            Where<CRLocation.bAccountID, Equal<Current<SOOrder.customerID>>,
            And<CRLocation.isActive, Equal<True>, And<MatchWithBranch<CRLocation.cBranchID>>>>>>))]
        [PXForeignReference(
            typeof(CompositeKey<
                Field<SOOrder.customerID>.IsRelatedTo<Location.bAccountID>,
                Field<SOOrderExt.usrLocationField>.IsRelatedTo<Location.locationID>
>))]
        public virtual Int32? UsrLocationField
        {
            get
            {
                return this._UsrLocationField;
            }
            set
            {
                this._UsrLocationField = value;
            }
        }

#endregion
  • Add the row selected event handler on the custom location field.
protected void SOOrder_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
            var row = (SOOrder)e.Row;
            cache.SetDefaultExt<SOOrderExt.usrLocationField>(e.Row);
    }

Hope it helps!

Regards,

Sweta


Forum|alt.badge.img

Hi @Vinay Koppula , @sweta68 ,

Thank you for your responses, First I created a new filed LocationCD and changed type into int and applied your suggestion as below.

 

#region LocationCD
        //[PXDBInt]
        //[PXDefault]
             [LocationActive(typeof(Where<Location.bAccountID, Equal<Current<APProforma.customerID>>,
            And<MatchWithBranch<Location.cBranchID>>>), DescriptionField = typeof(Location.descr), Visibility = PXUIVisibility.SelectorVisible)]
        [PXForeignReference(
            typeof(CompositeKey<
                Field<APProforma.customerID>.IsRelatedTo<Location.bAccountID>,
                Field<APProforma.locationCD>.IsRelatedTo<Location.locationID>>))]
        public virtual int? LocationCD { get; set; }
        public abstract class locationCD : PX.Data.BQL.BqlInt.Field<locationCD> { }
        #endregion

 

But after adding the filed to form and previewed, the field is gone.

So I removed it and uncomment PXDBInt , then it shows the field there. What is wrong with I have done there?


Vinay Koppula
Semi-Pro II
Forum|alt.badge.img+1

@oshadarodrigo64 PXDBInt is a datatype declaration, which is mandatory for any DAC field. Now, is it working as expected?

You can refer to @sweta68’s code where she also used the same LocationActive attribute. 


Forum|alt.badge.img

Hi @Vinay Koppula,

I uncomment PXDBInt and checked but the field is still not visible.


Vinay Koppula
Semi-Pro II
Forum|alt.badge.img+1

@oshadarodrigo64 Since the LocationActive attribute already consist of the PXDBInt, so no need to declare it again. Just use the below code to declare your DAC field. Also, check the code in the .aspx as well. 

#region LocationCD
LocationActive(typeof(Where<Location.bAccountID, Equal<Current<APProforma.customerID>>,
            And<MatchWithBranch<Location.cBranchID>>>), DescriptionField = typeof(Location.descr), Visibility = PXUIVisibility.SelectorVisible)]    
        [PXUIField(DisplayName = "Property")]
        public virtual int? LocationCD { get; set; }
        public abstract class locationCD: PX.Data.BQL.BqlInt.Field<locationCD> { }

#endregion



Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings