Skip to main content

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")]

       
                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

        dPXDefault()]

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

        PXUIField(DisplayName = "Valid For")]

        (PXDependsOnFields(typeof(SSPSetupActive.feature))]

         PXStringList(

        new stringb]

        {

            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 stringP] { 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 stringi] { SSS.SSP.Helper.Constant.ServiceOrder }, new stringr] { SSS.SSP.Helper.Messages.ServiceOrder });

        }

 

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

Help me in this…!

 

Thanks


 

 

 

 

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);              
            }
        }


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);
}
}

 

 


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.

 


Does ValidFor  field has commit changes in aspx?

 

 


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>


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.

 


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.


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 stringw] { SSS.SSP.Helper.Constant.ServiceOrder }, new stringw] { SSS.SSP.Helper.Messages.ServiceOrder });

ValidFor Field MatrixMode=true;

Grid  SyncPosition=false;

 

 


@NageswaraRaoAddanki60 Awesome 🙂 Thanks for sharing the update.

Please keep attributes like below.

MatrixMode = true

SyncPosition = true

 


Reply