Skip to main content
Answer

PX formula not populating

  • June 29, 2025
  • 6 replies
  • 129 views

I’m trying to create two pxformula attribued on a DAC.

        #region UpcomingCycleID
[PXInt]
[PXUIField(DisplayName = "Upcoming Cycle ID", Enabled = false)]
[PXFormula(
typeof(Search<
CycleDetail.cycleID,
Where<
CycleDetail.cycleMajor, Equal<Current<SeriesDetail.cycleMajor>>,
And<CycleDetail.cycleMinor, Equal<Current<SeriesDetail.cycleMinor>>,
And<CycleDetail.date, Greater<Current<AccessInfo.businessDate>>>>>>
))]
public virtual int? UpcomingCycleID { get; set; }
public abstract class upcomingCycleID : PX.Data.BQL.BqlInt.Field<upcomingCycleID> { }
#endregion


#region UpcomingCycleDate
[PXDate]
[PXUIField(DisplayName = "Upcoming Cycle Date", Enabled = false)]
[PXDependsOnFields(typeof(SeriesDetail.cycleMajor), typeof(SeriesDetail.cycleMinor))]
[PXFormula(
typeof(Search<
CycleDetail.date,
Where<
CycleDetail.cycleMajor, Equal<Current<SeriesDetail.cycleMajor>>,
And<CycleDetail.cycleMinor, Equal<Current<SeriesDetail.cycleMinor>>,
And<CycleDetail.date, Greater<AccessInfo.businessDate.FromCurrent>>>>,
OrderBy<Asc<CycleDetail.date>>>)
)]
public virtual DateTime? UpcomingCycleDate { get; set; }
public abstract class upcomingCycleDate : PX.Data.BQL.BqlDateTime.Field<upcomingCycleDate> { }
#endregion

CycleMajor and CycleMinor are a strings on the CycleDetailDAC.

I want these fields to be calculated on demand, hence the PXint and PXDate as opposed to PXDBInt etc.

But these aren’t being populated on the screen when I fill it in and they aren’t being populated in a generic inquiry.

I don’t even see the sql that’s would be from these two pxformula’s?

It’s just blank.

Best answer by VardanV

Hi Eberen,

Below updated my answer.

Based on my understanding of the PXFormula attribute, it may not work for your scenario.

The PXFormula attribute is designed to calculate a field’s value from other fields within the same data record. Additionally, it can update a value on the parent record if the DAC is related to another via the PXParent attribute.

However, in your case, I believe you’ll need to use the PXDBScalar attribute instead.

For more details about PXFormulaAttribute.

 

You should not use fields marked with the PXDBScalar attribute in BQL parameters such as Current<>, Optional<>, or Required<>.
Additionally, ensure that all fields referenced within the PXDBScalar expression are bound fields.

Update the PXDBScalar attribute by removing any usage of Current<>.

For more details about PXDBScalarAttribute

Thanks,

VardanV.

6 replies

  • Author
  • Freshman I
  • June 29, 2025

I tried to use PXDBScalar and it doesn’t work:

 

        [PXInt]
[PXDBScalar(typeof(
Search<CycleDetail.cycleID,
Where<CycleDetail.cycleMajor, Equal<cycleMajor.FromCurrent>,
And<CycleDetail.cycleMinor, Equal<cycleMinor.FromCurrent>,
And<CycleDetail.date, GreaterEqual<Current<AccessInfo.businessDate>>>>>,
OrderBy<Asc<CycleDetail.date>>>))]
[PXUIField(DisplayName = "Upcoming Cycle ID", Enabled = false)]
public int? UpcomingCycleID { get; set; }
public abstract class upcomingCycleID : BqlInt.Field<upcomingCycleID> { }

 


  • Author
  • Freshman I
  • June 29, 2025

Any way of doing it would be appreciated


Forum|alt.badge.img+8
  • Captain II
  • June 30, 2025

Hi ​@Eberen 

 

Generic Inquiries essentially pull data from the db and present them in a nicer UI.

An unbound field will show as NULL or 0.0 or 0 depending on if you have a PXDefault attribute on the field.

To calculate a field on demand in a GI, you should set the formula in the results grid.

 

Aleks 


VardanV
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • June 30, 2025

Hi Eberen,

Based on my understanding of the PXFormula attribute, it may not work for your scenario.

The PXFormula attribute is designed to calculate a field’s value from other fields within the same data record. Additionally, it can update a value on the parent record if the DAC is related to another via the PXParent attribute.

However, in your case, I believe you’ll need to use the PXDBScalar attribute instead.

For more details about PXFormulaAttribute.

Thanks,
VardanV.


  • Author
  • Freshman I
  • June 30, 2025

 

However, in your case, I believe you’ll need to use the PXDBScalar attribute instead.
 

For PXDBScalar you can take a look above at what I’m using, but I get an error variable @P1 not found.

It looks like when it creates the sql query, it doesn’t declare that variable:

 

declare @P0 as int = 1034
SELECT
/* SO.60.20.00, 16B08500 */
TOP (201) [SeriesDetail].[SeriesID],
[SeriesDetail].[SeriesRowID],
[SeriesDetail].[Bookid],
[SeriesDetail].[ShipDate],
[SeriesDetail].[CycleMajor],
[SeriesDetail].[CycleMinor],
(
SELECT
TOP (1) [CycleDetail].[CycleID]
FROM
[CycleDetail] [CycleDetail]
WHERE
(
[CycleDetail].[CycleID] = @P0
AND [CycleDetail].[CycleMajor] = @P1
AND [CycleDetail].[CycleMinor] = @P2
AND [CycleDetail].[Date] >= @P3
)
ORDER BY
[CycleDetail].[Date]
),
(
SELECT
TOP (1) [CycleDetail].[Date]
FROM
[CycleDetail] [CycleDetail]
WHERE
(
[CycleDetail].[CycleID] = @P0
AND [CycleDetail].[CycleMajor] = @P1
AND [CycleDetail].[CycleMinor] = @P2
AND [CycleDetail].[Date] >= @P3
)
ORDER BY
[CycleDetail].[Date]
)
FROM
[SeriesDetail] [SeriesDetail]
WHERE
([SeriesDetail].[SeriesID] = @P0)
ORDER BY
[SeriesDetail].[SeriesRowID] OPTION (OPTIMIZE FOR UNKNOWN)



 


VardanV
Jr Varsity III
Forum|alt.badge.img+1
  • Jr Varsity III
  • Answer
  • July 1, 2025

Hi Eberen,

Below updated my answer.

Based on my understanding of the PXFormula attribute, it may not work for your scenario.

The PXFormula attribute is designed to calculate a field’s value from other fields within the same data record. Additionally, it can update a value on the parent record if the DAC is related to another via the PXParent attribute.

However, in your case, I believe you’ll need to use the PXDBScalar attribute instead.

For more details about PXFormulaAttribute.

 

You should not use fields marked with the PXDBScalar attribute in BQL parameters such as Current<>, Optional<>, or Required<>.
Additionally, ensure that all fields referenced within the PXDBScalar expression are bound fields.

Update the PXDBScalar attribute by removing any usage of Current<>.

For more details about PXDBScalarAttribute

Thanks,

VardanV.