Usually Acumatica Drop-Down controls have fixed lists of values. Of course you can use PXStringListAttribute.SetList<…>(…) method do change list of values dynamically, but how to make it more handy.
The way I recommend you is to create an attribute that can encapsulate all the field related logic, so to use it you can just put the attribute on the proper place.
So the plan:
- Create an attribute that will be inherited from PXStringList and provide the values
- Create IPrefetchable class that can be automatically load all possible list from DB and cache it. In the same time Acumatica will auto-reset when the linked table is changed. This is really great performance optimization. Read more about caching data with database slots here.
- Use PXDatabase.GetSlot to retrieve the data from memory. If data is not yet cached or changed Acumatica platform will automatically will call Prefertch method to refresh data.
- Subscribe to RowSelected event and adjust the list using SetList method.
- Apply attribute on the field in the DAC
- (Optional) if your drop-down is located in the grid, make sure that your grid has MatrixMode=true
Please see the full example here:
Really hope it helps and have a nice development!
2 Replies to “Dynamic Drop-Down Control”
Thank you Stan, I have added a new step in the article.
Sergey, you should add that SetList will not work for grid columns without MatrixMode grid property set to true