Solved

How to Change the Dropdown list Values

  • 17 March 2022
  • 9 replies
  • 577 views

Userlevel 2
Badge

Hello,

I Have two dropdown list fields. I  need to  change the second dropdown values dynamically  based on first dropdown selected value.

Code below:-

 

#region Feature

        [PXDBString(30, IsKey = true, IsUnicode = true, InputMask = "")]

        [PXUIField(DisplayName = "Feature")]

        [PXStringList(

                new string[]

                {

                    SSS.SSP.Helper.Constant.Agree,

                    SSS.SSP.Helper.Constant.Inspect

                },

                new string[]

                {

                    SSS.SSP.Helper.Messages.Agree,

                    SSS.SSP.Helper.Messages.Inspect

                })]

        public virtual string Feature { get; set; }

        public abstract class feature : PX.Data.BQL.BqlString.Field<feature> { }

        #endregion

        #region ValidFor

        [PXDefault()]

        [PXDBString(5, IsKey = true, IsUnicode = true, InputMask = "")]

        [PXUIField(DisplayName = "Valid For")]

        [PXDependsOnFields(typeof(SSPSetupActive.feature))]

        [PXStringList(

        new string[]

        {

            SSS.SSP.Helper.Constant.Opportunity,

            SSS.SSP.Helper.Constant.ServiceOrder

        },

        new string[]

        {

            SSS.SSP.Helper.Messages.Opportunity,

             SSS.SSP.Helper.Messages.ServiceOrder

        })]

 

  protected void SSPSetupActive_Feature_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated del)

        {

            if (del != null)

                del(cache, e);

            var row = (SSPSetupActive)e.Row;

            if (row == null) return;

            //SSPSetupMaint rowExt = PXGraph.CreateInstance<SSPSetupMaint>();

            if (row.Feature == "Agree")

                PXStringListAttribute.SetList<SSPSetupActive.validFor>(cache, row, new string[] { SSS.SSP.Helper.Constant.Opportunity, SSS.SSP.Helper.Constant.ServiceOrder }, new string[] { SSS.SSP.Helper.Messages.Opportunity, SSS.SSP.Helper.Messages.ServiceOrder });

            else

                PXStringListAttribute.SetList<SSPSetupActive.validFor>(cache, row, new string[] { SSS.SSP.Helper.Constant.ServiceOrder }, new string[] { SSS.SSP.Helper.Messages.ServiceOrder });

        }

 

I tried this scenario. but, it’s not working.

Help me in this…!

 

Thanks


 

 

 

 

icon

Best answer by Naveen Boga 17 March 2022, 12:29

View original

9 replies

Userlevel 6
Badge +3

hi @NageswaraRaoAddanki60 ,

Code has to be implemented in the  ValidFor   Field fieldselecting event.

Here is the sample code to load details dynamically.

   protected virtual void SetUp_WarehouseMonitored_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            SetUp row = e.Row as SetUp;
            if (row != null)
            {
                var allowedValues = new List<string>();
                var allowedLabels = new List<string>();
                foreach (INSite site in PXSelect<INSite, Where<INSite.siteID, IsNotNull, And<INSite.siteID, NotEqual<SiteAttribute.transitSiteID>, And<Match<Current<AccessInfo.userName>>>>>>.Select(this))
                {
                    allowedValues.Add(site.SiteID.ToString());
                    allowedLabels.Add(site.SiteCD.Trim());
                }
                e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 500, true, typeof(SetUp.warehouseMonitored).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedLabels.ToArray(), false, null);              
            }
        }

Userlevel 7
Badge +17

Hi @NageswaraRaoAddanki60 

Hope you are looking for the below solution

If I'm understanding correctly, you 2 dropdown fields, and when you change 1st DropDown value, and based on that you wanted to load the 2nd DropDown values.

 DropDown1
 DropDown2

protected virtual void DAC1_DropDown1_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
DAC1 row = e.Row as DAC1;
if (row != null)
{
var allowedValues = new List<string>();
var allowedLabels = new List<string>();
foreach (INSite site in PXSelect<INSite, Where<INSite.siteID, IsNotNull, And<INSite.siteID, NotEqual<SiteAttribute.transitSiteID>, And<Match<Current<AccessInfo.userName>>>>>>.Select(this))
{
allowedValues.Add(site.SiteID.ToString());
allowedLabels.Add(site.SiteCD.Trim());
}
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 500, true, typeof(DAC1.DropDown1).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedLabels.ToArray(), false, null);
}
}

 

        // In the Below field selecting you need to add a condition load the values based on the 1st dropdown

 

protected virtual void DAC1_DropDown2_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
{
DAC1 row = e.Row as DAC1;
if (row != null)
{
var allowedValues = new List<string>();
var allowedLabels = new List<string>();
foreach (INSite site in PXSelect<INSite, Where<INSite.siteID, IsNotNull, And<INSite.siteID, NotEqual<SiteAttribute.transitSiteID>,
And<Match<Current<AccessInfo.userName>>,
And<Insite.Field1,Equal<Required<Insite.Field1>>>>>>>.Select(this, row.DropDown1))
{
allowedValues.Add(site.SiteID.ToString());
allowedLabels.Add(site.SiteCD.Trim());
}
e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 500, true, typeof(DAC1.DropDown2).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedLabels.ToArray(), false, null);
}
}


Also add one more EVENT to invoke the 2nd Dropdown fieldSelecting event when we change the 1st dropdown
 

protected virtual void DAC1_DropDown1_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
DAC1 row = e.Row as DAC1;
if (row != null)
{
ref Val = row.Dropdown1;
//The below code will invoke the 2nd DropDown field selecting event to load the values based on the 1st DropDown1
sender.RaiseFieldSelecting<SOLine.shipDate>(row, ref Validate, true);
}
}

 

 

Userlevel 2
Badge

Hi @praveenpo , @Naveen Boga In this way I tried. but, couldn't get. 
here dropdown 1 values are fixed , no need to change the these value.

 

 protected virtual void SSPSetupActive_ValidFor_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)

        {

            SSPSetupActive row = e.Row as SSPSetupActive;

            var allowedValues = new List<string>();

            var allowedLabels = new List<string>();

            if (row != null)

            {

                if (row.Feature == "Inspect")

                {

                    allowedValues.Add(SSS.SSP.Helper.Constant.ServiceOrder.ToString());

                    allowedLabels.Add(SSS.SSP.Helper.Messages.ServiceOrder.Trim());

                }

                e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 500, false, typeof(SSPSetupActive.validFor).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedLabels.ToArray(), false, null);

            }

        }

 

Thank you for your support.

 

Userlevel 6
Badge +3

Does ValidFor  field has commit changes in aspx?

 

 

Userlevel 2
Badge

Does ValidFor  field has commit changes in aspx?

 

 

Yes, @praveenpo ValidFor field commitchanges=true

<px:PXGridColumn  Type="DropDownList" CommitChanges="True" DataField="ValidFor" Width="70" ></px:PXGridColumn>

Badge +11

I must be missing something somewhere, but from what I can see from your original code, ‘ValidFor’ has a max length of 5. Why the result of field selecting should return 500 I’m not understanding. Also, both ‘combo’ fields are set as keys - (IsKey = true) - which leads me to believe it should be set as a key in the return state, but I could be wrong.

Interpreting the intellisense in Visual Studio, I believe this line:

e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 500, false, typeof(SSPSetupActive.validFor).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedLabels.ToArray(), false, null);

should be:

e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 5, true, typeof(SSPSetupActive.validFor).Name, true, -1, string.Empty, allowedValues.ToArray(), allowedLabels.ToArray(), false, null);

with the ‘-1’ possibly being something else as well, since it is ‘required’ in your code, if that is what this field is for.

This may not fix the problem, but I think it’s always good to understand what your code is doing, and if I’m wrong, then I’ll have learned something new today.

 

Userlevel 7
Badge +17

Hi @NageswaraRaoAddanki60  Are you having these fields in the FORM OR GRID?

If it is in GRID, please also add MatrixMode= true in the .aspx page.

Userlevel 2
Badge

Hi @Naveen Boga , @darylbowman , @praveenpo 

Thank you guys for supporting me. I achieved :heart_eyes:  

below  I added these code

 PXStringListAttribute.SetList<SSPSetupActive.validFor>(cache, row, new string[] { SSS.SSP.Helper.Constant.ServiceOrder }, new string[] { SSS.SSP.Helper.Messages.ServiceOrder });

ValidFor Field MatrixMode=true;

Grid  SyncPosition=false;

 

 

Userlevel 7
Badge +17

@NageswaraRaoAddanki60 Awesome 🙂 Thanks for sharing the update.

Please keep attributes like below.

MatrixMode = true

SyncPosition = true

 

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