Acumatica - 现场验证 ContractID
Acumatica - Field Verifying on ContractID
如何在费用收据中引用项目 ID,以便在保存之前验证该值?我想阻止使用非项目代码。
当我尝试发布下面的代码时,收到错误消息:
\App_RuntimeCode\ExpenseClaimDetailEntry.cs(31): error CS0426: The type name 'ContractID' does not exist in the type 'ExpenseClaimDetailEntry'
产生错误的代码:
protected virtual void _(Events.FieldVerifying<ExpenseClaimDetailEntry.ContractID> e) //<-- Line 31
{
if (e != null)
{
if ((string?)e.NewValue == "XXXXXXXX");
{
throw new PXSetPropertyException("Non-Project Code XXXXXXXX cannot be used in expense reciepts.");
}
}
}
感谢您的帮助!
编辑: 这是我的解决方案。使用 e.NewValue = null
和 e.Cancel = true
删除默认值,然后使用 PXSetPropertyException
阻止选择非项目代码。 YMMV.
protected void EPExpenseClaimDetails_contractID_FieldDefaulting(
PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = null;
e.Cancel = true; //Skip the standard FieldDefaulting code - It will revert ContractId to zero again!
}
protected void EPExpenseClaimDetails_contractID_FieldVerifying(Events.FieldVerifying<EPExpenseClaimDetails.contractID> e)
{
if ((int?)e.NewValue == 0)
{
throw new PXSetPropertyException("Error: Project 'X' not allowed in expense reciepts.", PXErrorLevel.Error);
}
}
对于每个 DAC 字段,声明了 两个变量。
1有一个属性(ContractID)。按照惯例,属性 以大写字母开头:
[ProjectDefault("EA", AccountType = typeof(expenseAccountID))]
[PXDBInt]
[PXDimensionSelector("CONTRACT", typeof(Search2<Contract.contractID, LeftJoin<EPEmployeeContract, On<EPEmployeeContract.contractID, Equal<Contract.contractID>, And<EPEmployeeContract.employeeID, Equal<Current2<employeeID>>>>>, Where<Contract.isActive, Equal<True>, And<Contract.isCompleted, Equal<False>, And<Where<Contract.nonProject, Equal<True>, Or2<Where<Contract.baseType, Equal<CTPRType.contract>, And<FeatureInstalled<FeaturesSet.contractManagement>>>, Or<Contract.baseType, Equal<CTPRType.project>, And2<Where<Contract.visibleInEA, Equal<True>>, And2<FeatureInstalled<FeaturesSet.projectModule>, And2<Match<Current<AccessInfo.userName>>, And<Where<Contract.restrictToEmployeeList, Equal<False>, Or<EPEmployeeContract.employeeID, IsNotNull>>>>>>>>>>>>, OrderBy<Desc<Contract.contractCD>>>), typeof(Contract.contractCD), new[] { typeof(Contract.contractCD), typeof(Contract.description), typeof(Contract.customerID), typeof(Contract.status) }, Filterable = true, ValidComboRequired = true, CacheGlobal = true, DescriptionField = typeof(Contract.description))]
[PXUIField(DisplayName = "Project/Contract")]
public virtual int? ContractID { get; set; }
属性用于获取或设置字段的值。
2 另一个变量是抽象的 class (contractID)。按照惯例,它以小写字母开头:
public abstract class contractID : BqlType<IBqlInt, int>.Field<contractID>
抽象class用于将字段作为指针引用时。它标识一个字段但不包含值。
在您的示例中,您声明了一个事件处理程序。为此,您需要使用抽象 class 因为事件指向字段而不是 getting/setting 字段值。将'ContractID'更改为'contractID':
void _(Events.FieldVerifying<ExpenseClaimDetail.contractID> e)
还有第二个错误,class EPExpenseClaimDetailsEntry
是图表,不是 DAC。字段位于 DAC(数据访问 class)中,而不是图表中。因此,对于事件处理程序通用类型,您必须使用 DAC EPExpenseClaimDetails
而不是图形 EPExpenseClaimDetailsEntry
。
如何在费用收据中引用项目 ID,以便在保存之前验证该值?我想阻止使用非项目代码。
当我尝试发布下面的代码时,收到错误消息:
\App_RuntimeCode\ExpenseClaimDetailEntry.cs(31): error CS0426: The type name 'ContractID' does not exist in the type 'ExpenseClaimDetailEntry'
产生错误的代码:
protected virtual void _(Events.FieldVerifying<ExpenseClaimDetailEntry.ContractID> e) //<-- Line 31
{
if (e != null)
{
if ((string?)e.NewValue == "XXXXXXXX");
{
throw new PXSetPropertyException("Non-Project Code XXXXXXXX cannot be used in expense reciepts.");
}
}
}
感谢您的帮助!
编辑: 这是我的解决方案。使用 e.NewValue = null
和 e.Cancel = true
删除默认值,然后使用 PXSetPropertyException
阻止选择非项目代码。 YMMV.
protected void EPExpenseClaimDetails_contractID_FieldDefaulting(
PXCache sender, PXFieldDefaultingEventArgs e)
{
e.NewValue = null;
e.Cancel = true; //Skip the standard FieldDefaulting code - It will revert ContractId to zero again!
}
protected void EPExpenseClaimDetails_contractID_FieldVerifying(Events.FieldVerifying<EPExpenseClaimDetails.contractID> e)
{
if ((int?)e.NewValue == 0)
{
throw new PXSetPropertyException("Error: Project 'X' not allowed in expense reciepts.", PXErrorLevel.Error);
}
}
对于每个 DAC 字段,声明了 两个变量。
1有一个属性(ContractID)。按照惯例,属性 以大写字母开头:
[ProjectDefault("EA", AccountType = typeof(expenseAccountID))]
[PXDBInt]
[PXDimensionSelector("CONTRACT", typeof(Search2<Contract.contractID, LeftJoin<EPEmployeeContract, On<EPEmployeeContract.contractID, Equal<Contract.contractID>, And<EPEmployeeContract.employeeID, Equal<Current2<employeeID>>>>>, Where<Contract.isActive, Equal<True>, And<Contract.isCompleted, Equal<False>, And<Where<Contract.nonProject, Equal<True>, Or2<Where<Contract.baseType, Equal<CTPRType.contract>, And<FeatureInstalled<FeaturesSet.contractManagement>>>, Or<Contract.baseType, Equal<CTPRType.project>, And2<Where<Contract.visibleInEA, Equal<True>>, And2<FeatureInstalled<FeaturesSet.projectModule>, And2<Match<Current<AccessInfo.userName>>, And<Where<Contract.restrictToEmployeeList, Equal<False>, Or<EPEmployeeContract.employeeID, IsNotNull>>>>>>>>>>>>, OrderBy<Desc<Contract.contractCD>>>), typeof(Contract.contractCD), new[] { typeof(Contract.contractCD), typeof(Contract.description), typeof(Contract.customerID), typeof(Contract.status) }, Filterable = true, ValidComboRequired = true, CacheGlobal = true, DescriptionField = typeof(Contract.description))]
[PXUIField(DisplayName = "Project/Contract")]
public virtual int? ContractID { get; set; }
属性用于获取或设置字段的值。
2 另一个变量是抽象的 class (contractID)。按照惯例,它以小写字母开头:
public abstract class contractID : BqlType<IBqlInt, int>.Field<contractID>
抽象class用于将字段作为指针引用时。它标识一个字段但不包含值。
在您的示例中,您声明了一个事件处理程序。为此,您需要使用抽象 class 因为事件指向字段而不是 getting/setting 字段值。将'ContractID'更改为'contractID':
void _(Events.FieldVerifying<ExpenseClaimDetail.contractID> e)
还有第二个错误,class EPExpenseClaimDetailsEntry
是图表,不是 DAC。字段位于 DAC(数据访问 class)中,而不是图表中。因此,对于事件处理程序通用类型,您必须使用 DAC EPExpenseClaimDetails
而不是图形 EPExpenseClaimDetailsEntry
。