Select distinct values in Acumatica selector

Hello everybody,

today I want to post how to make distinct select from some column in Acumatica.

So, imagine that you've decided not to normalize some column for Acumatica to SOOrder class. For example like this:

public class SOOrderExtPXCacheExtension<SOOrder>
    {
        #region Region
        public abstract class region : IBqlField
        {
        }
        [PXDBString(255)]
        [PXUIField(DisplayName = "Region", Visibility = PXUIVisibility.Visible)]
        public virtual string Region { getset; }
        #endregion

Then in other place, if you need to make distinct selector for Region, you can use code like this:

#region Region
 public abstract class region : IBqlField
 {
 }
 [PXDBString(255)]
 [PXUIField(DisplayName = "Region", Visibility = PXUIVisibility.Visible)]
 [PXSelector(typeof(Search4<SOOrderExt.regionAggregate<GroupBy<SOOrderExt.region>>>), typeof(SOOrderExt.region))]
 public virtual string Region { getset; }
 #endregion

With such apporach you can get distinct list of whatever you have in your tables. But keep in mind, that for repetative data it's better to use separate table then play with distinct values. I prefer not to use such approach in production for mine customers because on huge data sets such approach can cause significant slowdown of Acumatica.

No Comments

Add a Comment