Solved

Load data in location field based on selected customer

  • 22 March 2023
  • 9 replies
  • 160 views

Userlevel 3
Badge

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.

 

icon

Best answer by Vinay Koppula 24 March 2023, 10:59

View original

9 replies

Userlevel 4
Badge +2

Your code has a typo

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

Should be LocationID

Userlevel 3
Badge

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?

 

Userlevel 5
Badge +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)]

     

Userlevel 5
Badge +1

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

Userlevel 7
Badge +10

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

Userlevel 3
Badge

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?

Userlevel 5
Badge +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. 

Userlevel 3
Badge

Hi @Vinay Koppula,

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

Userlevel 5
Badge +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


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved