Skip to main content
Solved

Clear Dependent Fields


I have 2 custom fields, Customer and Project, that are required. The second field is a selector that is dependent on the value that is in the first field.

Customer Field:

        [PXDBInt]
        [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
        [PXUIField(DisplayName = "Customer", Required = true)]
        [PXSelector(typeof(SearchFor<Customer.bAccountID>
                             .In<SelectFrom<Customer>
                             .InnerJoin<BAccount2>
                             .On<Customer.bAccountID.IsEqual<BAccount2.bAccountID>>>),
                    new Type[] {
                        typeof(Customer.bAccountID),
                        typeof(BAccount2.acctName)
                    },
                    DescriptionField = typeof(BAccount2.acctName))]

        public int? UsrMOSCustomerID { get; set; }
        public abstract class usrMOSCustomerID : BqlInt.Field<usrMOSCustomerID> { }

Project Field:

       [PXDBString]
       [PXDefault(PersistingCheck = PXPersistingCheck.Nothing)]
       [PXUIField(DisplayName = "Project", Required = true)]
       [PXSelector(typeof(SearchFor<MOSCustomerProject.mosprojectid>
           .In<SelectFrom<MOSCustomerProject>
           .Where<MOSCustomerProject.customerID.IsEqual<usrMOSCustomerID.FromCurrent>>>),
               new Type[] {
                   typeof(MOSCustomerProject.mosprojectid),
                   typeof(MOSCustomerProject.descr)
               })]

       public string UsrMOSProjectID { get; set; }
       public abstract class usrMOSProjectID : BqlString.Field<usrMOSProjectID> { }

 

The thing that I can’t figure out is how to clear the second field when the first field changes. The specific use case is I have two Customers. Customer #1 has projects TEST1 and TEST2, customer #2 has projects TEST3 and TEST4. First, I select Customer #1 and TEST2. Then I change the customer to Customer #2. At this point, Project still shows TEST2. I think it should show nothing.

Can I have it do what I want and if so, how?
 

Best answer by RohitRattan88

@robtrainer6184 

Have you looked at your ASP code:

on your ASPX file make sure you have added CommitChanges=True and AutoRefresh=true properties, see below:

ref: graph - Make a form field selection values dependent on another field value - Stack Overflow

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

6 replies

RohitRattan88
Acumatica Moderator
Forum|alt.badge.img+4
  • Acumatica Moderator
  • 253 replies
  • Answer
  • November 6, 2023

@robtrainer6184 

Have you looked at your ASP code:

on your ASPX file make sure you have added CommitChanges=True and AutoRefresh=true properties, see below:

ref: graph - Make a form field selection values dependent on another field value - Stack Overflow


YEs, I have both of those set on both fields.

 


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

Hi @robtrainer6184,

Additionally, you can use the BQL to set the value in the PXDefault attribute. Below is a quick example you can refer to,

[PXDefault(typeof(Search<EPEmployee.bAccountID, Where<EPEmployee.userID, Equal<Current<AccessInfo.userID>>>>), PersistingCheck=PXPersistingCheck.Nothing)]

For details on the PXDefaultAttribute refer https://help.acumatica.com/(W(4))/Help?ScreenId=ShowWiki&pageid=1853593a-65f0-40e1-b685-14749a35128d

Feel free to post if you have further questions. Good Luck.!

 

 


 @RohitRattan88 I just noticed the part about validating using PXFormula. Adding that causes it to show an error for the Project field.

Is there a way to have it clear the field?

@Vignesh Ponnusamy  The default value that I want is empty.


Vignesh Ponnusamy
Acumatica Moderator
Forum|alt.badge.img+5

@robtrainer6184,

In the case, you can try use the FieldUpdated event where you can check the previous values based on which you can clear the value on the other field. Below is an example you can try,

    public class SOOrderEntry_Extension : PXGraphExtension<PX.Objects.SO.SOOrderEntry>
    {
        #region Event Handlers
        protected void SOOrder_UsrMOSCustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
        {
            var row = (SOOrder)e.Row;
            SOOrderExt rowExt = row.GetExtension<SOOrderExt>();
            if (e.OldValue != rowExt.UsrMOSCustomerID)
                rowExt.UsrMOSProjectID = "";
        }
        #endregion
    }

 


Thank you. All of this help me to get it working.


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