Skip to main content
Answer

Creating a PXProjection

  • March 21, 2025
  • 2 replies
  • 96 views

Forum|alt.badge.img

I am trying to create a projection query this is the sql query which works. I tried something like this
[PXProjection(typeof(
Select4<
    PMBudget,
    Where2<
        Where<PMBudget.type, Equal<AccountType.income>>,
        Or<
            Where<PMBudget.type, Equal<AccountType.expense>,
            And<ParentChildContractExt.usrIsChildProject, Equal<True>>>>>,
            And<PMBudget.accountGroupID, In<            Select<ProjectTransferRequestSetup,Where<ProjectTransferRequestSetup.transferAccountGroup, IsNotNull>>>>>>>>,
    Aggregate<
        GroupBy<PMBudget.projectID,
        Sum<PMBudget.curyRevisedAmount,
        Sum<PMBudget.curyAmount,
        Sum<PMBudget.curyInvoicedAmount,
        Sum<PMBudget.curyActualAmount,
        Sum<PMBudget.curyInclTaxAmount,
        Sum<PMBudget.curyTotalRetainedAmount,
        Sum<PMBudget.curyAmountToInvoice,
        Sum<PMBudget.curyChangeOrderAmount>>>>>>>>>>>))]
it doesnot work


SELECT

    b.ProjectID,

    c.ContractCD,

    c.usrIsChildProject,

   

    -- Aggregated Fields

    SUM(b.CuryRevisedAmount) AS Total_CuryRevisedAmount,

    SUM(b.CuryAmount) AS Total_CuryAmount,

    SUM(b.CuryInvoicedAmount) AS Total_CuryInvoicedAmount,

    SUM(b.CuryActualAmount) AS Total_CuryActualAmount,

    SUM(b.CuryInclTaxAmount) AS Total_CuryInclTaxAmount,

    SUM(b.CuryTotalRetainedAmount) AS Total_CuryTotalRetainedAmount,

    SUM(b.CuryAmountToInvoice) AS Total_CuryAmountToInvoice,

    SUM(b.CuryChangeOrderAmount) AS Total_CuryChangeOrderAmount

 

FROM PMBudget b

LEFT JOIN Contract c ON b.ProjectID = c.ContractID

 

WHERE c.ContractCD = 'SL-P-25-0017'  -- Filter for specific contract

AND (

    b.Type = 'I'  -- Include all income budgets

    OR (

        b.Type = 'E'

        AND c.usrIsChildProject = 1  -- Only include expenses for child projects

        AND b.AccountGroupID IN (SELECT TransferAccountGroup FROM ProjectTransferRequestSetup) -- Filter by ProjectTransferRequestSetup.transferAccountGroup

    )

)

 

GROUP BY

    b.ProjectID,

    c.ContractCD,

    c.usrIsChildProject  -- Grouping similar to projection

 

ORDER BY b.ProjectID;


 

Best answer by ron

I think main problem was the select4. I had to change to select2 as it allows table joins. The select4 does not allow table joins.

2 replies

Forum|alt.badge.img+5
  • Jr Varsity I
  • March 27, 2025

Hi ​@ron,

To properly translate your SQL query into an Acumatica PXProjection, we need to ensure that:

Joins: Use PXSelectJoin or Select4 for complex joins.
Conditions: Use Where<> and Where2<> clauses for multiple conditions.
Aggregation: Use the Aggregate<> clause with Sum<> and GroupBy<>.
Subqueries: Handle IN clauses using Select<> within In<>.

 

Here’s a corrected version of your PXProjection that matches the SQL query:

[PXProjection(typeof(
    Select4<
        PMBudget,
        LeftJoin<Contract, On<PMBudget.projectID, Equal<Contract.contractID>>>,
        Where2<
            Where<PMBudget.type, Equal<AccountType.income>,
            Or<Where<PMBudget.type, Equal<AccountType.expense>,
                And<ParentChildContractExt.usrIsChildProject, Equal<True>,
                And<PMBudget.accountGroupID, In<
                    Select<ProjectTransferRequestSetup.transferAccountGroup,
                        Where<ProjectTransferRequestSetup.transferAccountGroup, IsNotNull>>>>>
>>>>,
            And<Contract.contractCD, Equal<Required<Contract.contractCD>>>>,
        Aggregate<
            GroupBy<PMBudget.projectID,
            GroupBy<Contract.contractCD,
            GroupBy<ParentChildContractExt.usrIsChildProject,
            Sum<PMBudget.curyRevisedAmount,
            Sum<PMBudget.curyAmount,
            Sum<PMBudget.curyInvoicedAmount,
            Sum<PMBudget.curyActualAmount,
            Sum<PMBudget.curyInclTaxAmount,
            Sum<PMBudget.curyTotalRetainedAmount,
            Sum<PMBudget.curyAmountToInvoice,
            Sum<PMBudget.curyChangeOrderAmount>>>>>>>>>>>))]
public class PMBudgetProjection : IBqlTable
{
    #region ProjectID
    [PXDBInt(IsKey = true, BqlField = typeof(PMBudget.projectID))]
    public virtual int? ProjectID { get; set; }
    public abstract class projectID : PX.Data.BQL.BqlInt.Field<projectID> { }
    #endregion

 

    #region ContractCD
    [PXDBString(BqlField = typeof(Contract.contractCD))]
    public virtual string ContractCD { get; set; }
    public abstract class contractCD : PX.Data.BQL.BqlString.Field<contractCD> { }
    #endregion

 

    #region UsrIsChildProject
    [PXDBBool(BqlField = typeof(ParentChildContractExt.usrIsChildProject))]
    public virtual bool? UsrIsChildProject { get; set; }
    public abstract class usrIsChildProject : PX.Data.BQL.BqlBool.Field<usrIsChildProject> { }
    #endregion

 

    #region TotalCuryRevisedAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyRevisedAmount))]
    public virtual decimal? TotalCuryRevisedAmount { get; set; }
    public abstract class totalCuryRevisedAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryRevisedAmount> { }
    #endregion

 

    #region TotalCuryAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyAmount))]
    public virtual decimal? TotalCuryAmount { get; set; }
    public abstract class totalCuryAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryAmount> { }
    #endregion

 

    #region TotalCuryInvoicedAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyInvoicedAmount))]
    public virtual decimal? TotalCuryInvoicedAmount { get; set; }
    public abstract class totalCuryInvoicedAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryInvoicedAmount> { }
    #endregion

 

    #region TotalCuryActualAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyActualAmount))]
    public virtual decimal? TotalCuryActualAmount { get; set; }
    public abstract class totalCuryActualAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryActualAmount> { }
    #endregion

 

    #region TotalCuryInclTaxAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyInclTaxAmount))]
    public virtual decimal? TotalCuryInclTaxAmount { get; set; }
    public abstract class totalCuryInclTaxAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryInclTaxAmount> { }
    #endregion

 

    #region TotalCuryTotalRetainedAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyTotalRetainedAmount))]
    public virtual decimal? TotalCuryTotalRetainedAmount { get; set; }
    public abstract class totalCuryTotalRetainedAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryTotalRetainedAmount> { }
    #endregion

 

    #region TotalCuryAmountToInvoice
    [PXDBDecimal(BqlField = typeof(PMBudget.curyAmountToInvoice))]
    public virtual decimal? TotalCuryAmountToInvoice { get; set; }
    public abstract class totalCuryAmountToInvoice : PX.Data.BQL.BqlDecimal.Field<totalCuryAmountToInvoice> { }
    #endregion

 

    #region TotalCuryChangeOrderAmount
    [PXDBDecimal(BqlField = typeof(PMBudget.curyChangeOrderAmount))]
    public virtual decimal? TotalCuryChangeOrderAmount { get; set; }
    public abstract class totalCuryChangeOrderAmount : PX.Data.BQL.BqlDecimal.Field<totalCuryChangeOrderAmount> { }
    #endregion

Hope this helps!


Forum|alt.badge.img
  • Author
  • Varsity I
  • Answer
  • March 27, 2025

I think main problem was the select4. I had to change to select2 as it allows table joins. The select4 does not allow table joins.