How To Use Pxdbscalar With Pxprojection

How to use PXDBScalar with PXProjection

Hello everybody,

today I want to write a few words about how to use PXDBscalar in connection with PXProjection and is it possible at all.

First of all want to say that it's defientely a possiblity. Take a look on this sample of implementation:

[Serializable]
[PXProjection(typeof(Select2<FABookBalance,
	LeftJoin<FABookHistoryOn<FABookHistory.assetIDEqual<FABookBalance.assetID>,
	And<FABookHistory.bookIDEqual<FABookBalance.bookID>,
	And<FABookHistory.finPeriodIDEqual<IsNull<FABookBalance.currDeprPeriodFABookBalance.lastPeriod>>>>>,
	InnerJoin<FABookOn<FABook.bookIDEqual<FABookBalance.bookID>>>>>), new Type[] { typeof(FABookBalance) })]
[PXCacheName(Messages.FABookBalance)]
public partial class FABookBalance : PX.Data.IBqlTable
{

as you see, above goes projection of FABookBalance, FABookHistory, FABook. Three DAC classes. And then take a look on how it can be used in PXDBScalar:

public abstract class classID : PX.Data.BQL.BqlInt.Field<classID> { }
protected Int32? _ClassID;
[PXInt()]
[PXDBScalar(typeof(Search<FixedAsset.classIDWhere<FixedAsset.assetIDEqual<FABookBalance.assetID>>>))]
[PXDefault(typeof(Search<FixedAsset.classIDWhere<FixedAsset.assetIDEqual<Current<FABookBalance.assetID>>>>))] [PXSelector(typeof(Search<FixedAsset.assetID>), SubstituteKey = typeof(FixedAsset.assetCD), CacheGlobal = true, DescriptionField = typeof(FixedAsset.description))] [PXUIField(DisplayName = "Asset Class", Enabled = false)] public virtual Int32? ClassID { get { return this._ClassID; } set { this._ClassID = value; } }

As you see from code sample, it has calculation from totaly another class even: FixedAsset. Pretty cool? 

Take a look on another example:

[Serializable]
    [PXBreakInheritance]
    [PXCacheName(TX.TableName.SODET_PART)]
    [PXProjection(typeof(Select<FSSODet,
                        Where<
                            FSSODet.lineTypeEqual<ListField_LineType_ALL.Inventory_Item>,
                            Or<FSSODet.lineTypeEqual<ListField_LineType_ALL.Comment_Part>,
                            Or<FSSODet.lineTypeEqual<ListField_LineType_ALL.Instruction_Part>>>>>), Persistent = true)]
    public class FSSODetPart : FSSODet
    {

and take notice of PXDBScalar usage inside of that class:

        public new abstract class planType : PX.Data.BQL.BqlString.Field<planType> { }


        [PXDBScalar(typeof(Search<INPlanType.planTypeWhere<INPlanType.inclQtyFSSrvOrdBookedEqual<True>>>))]
        [PXDefault(typeof(Search<INPlanType.planTypeWhere<INPlanType.inclQtyFSSrvOrdBookedEqual<True>>>), PersistingCheck = PXPersistingCheck.Nothing)]         [PXString(SOOrderTypeOperation.orderPlanType.Length, IsFixed = true)]         public override String PlanType         {             get             {                 return this._PlanType;             }             set             {                 this._PlanType = value;             }         }

As you can see from he code sample, PXProjection is built on FSSODet table only, but for calculation of it's value it uses INPlantype table. 

Summary

If to summarize, you can use PXProjection with PXDBScalar. The only word of warning I have is during web api calls, you may potentially face cases when Acumatica team decided to make optimization, and PXDBSCalar can be skipped. There are ways of dealing with skipping of it also with help of attribute PXDependsOnField.

Comments are closed