Solved

Clear Dependent Fields

  • 6 November 2023
  • 6 replies
  • 66 views

Userlevel 1

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?
 

icon

Best answer by RohitRattan88 6 November 2023, 21:30

View original

6 replies

Userlevel 7
Badge +4

@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

Userlevel 1

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

 

Userlevel 7
Badge +4

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.!

 

 

Userlevel 1

 @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.

Userlevel 7
Badge +4

@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
}

 

Userlevel 1

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

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