How do I reference the project ID in an Expense Receipt, to validate the value before it is saved? I would like to block use of the non-project code.
When I attempt to publish the code below, I receive the error:
\App_RuntimeCode\ExpenseClaimDetailEntry.cs(31): error CS0426: The type name 'ContractID' does not exist in the type 'ExpenseClaimDetailEntry'
The code that produces the error:
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.");
}
}
}
Thank you for your help!
Edit: This is my solution. Remove the default value using e.NewValue = null and e.Cancel = true, then block selection of the non-project code using 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);
}
}