Solved

Modify DropDown List Field dynamically

  • 15 December 2020
  • 2 replies
  • 42 views

Userlevel 1

Hello, 

I manage to create a custom filed and set it to dropdown list but only with static values 
code below : 

[PXDBInt]

[PXIntList(new int[] {0, 1, 2, 3}, new string[] {"North", "East", "South", "West"})]

[PXUIField(DisplayName="ListLibre1")]

 

I want to modify the dropdown list values dynamically and directly on the screen.

How it can be done ?

 

Thanks :) 

icon

Best answer by Naveen B 15 December 2020, 11:58

Hello @SadokHanini 

 

To load the drop-down values dynamically, then we need to use fieldselecting event to load the values dynamically. Please find the example below. 

 


        protected virtual void SOOrder_UsrKNOrderReturnCodes_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            SOOrder row = e.Row as SOOrder;
            if (row != null)
            {
                List<string> allowedValues = new List<string>();

                foreach (KNAMICodes objAMICodes in PXSelect<KNAMICodes, Where<KNAMICodes.codeType, Equal<AMIConstants.ReturnCodes>,
                    And<KNAMICodes.isActive, Equal<True>>>>.Select(Base))
                {
                    allowedValues.Add(objAMICodes.Codecd);
                }
                e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 10, true, typeof(KNAMICodes.codecd).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedValues.ToArray(), false, null);
                ((PXStringState)e.ReturnState).MultiSelect = false;
            }
        }

 

I hope this will help you!!
 

View original

2 replies

Userlevel 4
Badge +1

Hello @SadokHanini 

 

To load the drop-down values dynamically, then we need to use fieldselecting event to load the values dynamically. Please find the example below. 

 


        protected virtual void SOOrder_UsrKNOrderReturnCodes_FieldSelecting(PXCache cache, PXFieldSelectingEventArgs e)
        {
            SOOrder row = e.Row as SOOrder;
            if (row != null)
            {
                List<string> allowedValues = new List<string>();

                foreach (KNAMICodes objAMICodes in PXSelect<KNAMICodes, Where<KNAMICodes.codeType, Equal<AMIConstants.ReturnCodes>,
                    And<KNAMICodes.isActive, Equal<True>>>>.Select(Base))
                {
                    allowedValues.Add(objAMICodes.Codecd);
                }
                e.ReturnState = PXStringState.CreateInstance(e.ReturnState, 10, true, typeof(KNAMICodes.codecd).Name, false, -1, string.Empty, allowedValues.ToArray(), allowedValues.ToArray(), false, null);
                ((PXStringState)e.ReturnState).MultiSelect = false;
            }
        }

 

I hope this will help you!!
 

Userlevel 4
Badge +1

Sadok,

This link also, you can review and verify once.

https://acumatica.programmingpedia.net/en/tutorial/9392/modifying-items-in-a-dropdown-list

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 — 2020  Acumatica, Inc. All rights reserved