Loading ...

PXAggregateAttribute usage for saving of your development time

Hi everybody,

today I want to share one of the insights from code and code, which was conducted by Stéphane Bélanger, and which seems useful, also may be controversial. But still, you may like it. So let me introduce or re-introduce PXAggregateAttribute .

 

If to sum up, purpose of PXAggregateAttribute, is merging of couple of attributes into single one. Consider following situation. You need to have selector Active customer over multiple places in Acumatica: at Purchase orders form, and Sales order form and at Shipment form. And difference between them will be zero, or close to that. Wouldn't that be nice, to declare this attribute in one place, and then to re-use it everywhere else? Of course yes. And for that purpose, Acumatica introduced attribute PXAggregateAttribute. 

Below goes code sample, of how that can be used, and re-used:

[PXInt()]
[PXUIField(DisplayName = "Active Customer")]
[PXDefault()]
[PXSelector(typeof(Search<BAccountR.bAccountID,
    Where<BAccountR.status, Equal<BAccount.status.active>>>))]
public class ActiveCustomer : PXAggregateAttribute {}
 
 
public class SOShipmentExt : PXCacheExtension<SOShipment>
{
    public abstract class activeCustomer : PX.Data.BQL.BqlInt.Field<activeCustomer> { }
 
    // Acuminator disable once PX1030 PXDefaultIncorrectUse [For demonstration purposes that will be sufficient]
    [ActiveCustomer]
    public Int32? ActiveCustomer { get; set; }
}
 
public class POOrderExt : PXCacheExtension<POOrder>
{
    public abstract class activeCustomer : PX.Data.BQL.BqlInt.Field<activeCustomer> { }
 
    // Acuminator disable once PX1030 PXDefaultIncorrectUse [For demonstration purposes that will be sufficient]
    [ActiveCustomer]
    public Int32? ActiveCustomer { get; set; }
}
 
public class SOOrderExt : PXCacheExtension<SOOrder>
{
    public abstract class activeCustomer : PX.Data.BQL.BqlInt.Field<activeCustomer> { }
 
    // Acuminator disable once PX1030 PXDefaultIncorrectUse [For demonstration purposes that will be sufficient]
    [ActiveCustomer]
    public Int32? ActiveCustomer { get; set; }
}
 As you can see, above our class ActiveCustomer, we've declared bundle of attributes, and then everywhere else, we've used them, but instead of duplication of code, we've re-used them as single line.