Skip to main content
Answer

Non Project Code Validation

  • February 3, 2021
  • 2 replies
  • 276 views

I am trying to perform validation on the project for screen EP307000.

 

Under Project Preferences we have defined the non project code as ‘X’.


What I want to achieve is to prevent users from saving their time entry when they have not selected their project, and it defaults on ‘X’.

I would appreciate any help.

Best answer by Cesar Betances

If you are trying to add validation at the moment the user presses the Save button on your screen, you could try to add your validation on Persist() method. You could:

-Create graph extension of that screen’s graph.

-Override Persist() method.

-On this override you will add your validation, and then call base(persist) method, similar to this:

 


[PXOverride]
public void Persist(Action baseMethod)
{
if( YourValidationFailed) throw new Exception("Fail!"); //Add your validation code

baseMethod(); //Call base method
}

 

2 replies

Forum|alt.badge.img+2
  • Acumatica Moderator
  • Answer
  • February 16, 2021

If you are trying to add validation at the moment the user presses the Save button on your screen, you could try to add your validation on Persist() method. You could:

-Create graph extension of that screen’s graph.

-Override Persist() method.

-On this override you will add your validation, and then call base(persist) method, similar to this:

 


[PXOverride]
public void Persist(Action baseMethod)
{
if( YourValidationFailed) throw new Exception("Fail!"); //Add your validation code

baseMethod(); //Call base method
}

 


Forum|alt.badge.img
  • Jr Varsity I
  • August 26, 2021

I was able to solve this for Expense Receipts using a customization:

namespace PX.Objects.EP
{
public class ExpenseClaimDetailEntry_Extension : PXGraphExtension<ExpenseClaimDetailEntry>
{
#region Event Handlers

protected virtual void EPExpenseClaimDetails_contractID( Events.FieldVerifying<EPExpenseClaimDetails.contractID> e)
{

if (e != null)
{

if ((int)e.NewValue == 0)
{
throw new PXSetPropertyException("Non-Project Code XXXXXXXX cannot be used in expense reciepts.", PXErrorLevel.RowError);
}
}
}

#endregion
}
}