If this looks familiar, I asked a question the other day about this issue. I resolved everything in that question except for this part, so I am re-asking based on the remaining open issue I am having.
I added a column to a selector “typeof(USRBudgetTotalExt2.usrBudgetTotal)”. The column value is being derived from an extension. In that extension, I want to execute a BQL query to get a sum of the curyRevisedAmount field from the PMBudget table.
My code currently returns a hardcoded amount of 100 just for proof of concept that my selector is working and returning the value for the column based on the extension.
Looking good so far! :-)
This is the code at this point.
namespace PX.Objects.PO
{
//[PXNonInstantiatedExtension]
public class PO_POLine_ExistingColumn : PXCacheExtension<PX.Objects.PO.POLine>
{
public static bool IsActive() => true;
#region ProjectID
[PXMergeAttributes(Method = MergeMethod.Append)]
[PXCustomizeSelectorColumns(
typeof(PX.Objects.PM.PMProject.contractCD),
typeof(PX.Objects.PM.PMProject.description),
typeof(USRBudgetTotalExt2.usrBudgetTotal),
typeof(PX.Objects.PM.PMProject.status),
typeof(PX.Objects.PM.PMProject.customerID),
typeof(PX.Objects.AR.Customer.acctName),
typeof(PX.Objects.PM.PMProject.curyID))]
public int? ProjectID { get; set; }
#endregion
}
public sealed class USRBudgetTotalExt2 : PXCacheExtension<PX.Objects.CT.Contract>
{
public static bool IsActive() => true;
#region UsrBudgetTotal
public abstract class usrBudgetTotal : PX.Data.BQL.BqlDecimal.Field<usrBudgetTotal> { }
protected decimal? _UsrBudgetTotal;
[PXDecimal]
[PXUnboundDefault(PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Budget Total", Visibility = PXUIVisibility.SelectorVisible, Visible = true)]
public decimal? UsrBudgetTotal
{
get
{
try
{
//returns the correct contract ID
var joe = Base.ContractID;
//PMBudget budget = SelectFrom<PMBudget>
// .Where<PMBudget.projectID.IsEqual<PMProject.contractID.FromCurrent>>
// .AggregateTo<GroupBy<PMBudget.projectID>, Sum<PMBudget.curyRevisedAmount>>.View.Select(Base);
return 100;
}
catch
{
return 0;
}
}
set
{
this._UsrBudgetTotal = value;
}
}
#endregion
}
No matter what I try, I am getting errors that I cannot execute code from within a property.
This code works in the ProjectEntry_Extension I created so I know the query is correct.
PMBudget budget = SelectFrom<PMBudget>
.Where<PMBudget.projectID.IsEqual<PMProject.contractID.FromCurrent>>
.AggregateTo<GroupBy<PMBudget.projectID>, Sum<PMBudget.curyRevisedAmount>>.View.Select(Base);
Is there some workaround I can do to be able to execute this statement and be able to return from my USRBudgetTotalExt2 extension? If not, I think that my answer to my client is that this is not possible. I hate to reply with that, but maybe that is just the way it is.
Best answer by Django
View original