Skip to main content

Hi i cannot work out what i am missing. I want a warning not a stop message when an AP Bill is created/updated if the Total value is 0. It works but i cannot save the Bill with a zero as the error keeps presenting on save. I have tried Row Inserted but that triggers to early.

 

  public class APInvoiceEntry_Extension : PXGraphExtension<PX.Objects.AP.APInvoiceEntry>
  {
    #region Event Handlers

    protected void APInvoice_RowPersisted(PXCache cache, PXRowPersistedEventArgs e, PXRowPersisted InvokeBaseHandler)
    {
      if(InvokeBaseHandler != null)
        InvokeBaseHandler(cache, e);
      var row = (APInvoice)e.Row;
                       if (row !=null && row.CuryLineTotal == 0)
            {
                throw new PXSetPropertyException("The document total is zero", PXErrorLevel.Warning);
            }
    }

@dcomerford  - Please try the following:  

 

protected void APInvoice_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting InvokeBaseHandler)
{
  if (InvokeBaseHandler != null)
    InvokeBaseHandler(cache, e);
  var row = (APInvoice)e.Row;
  if (row != null && row.CuryLineTotal == 0 && (e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update))
  {
    cache.RaiseExceptionHandling<APInvoice.curyLineTotal>(e.Row, row.CuryLineTotal, new PXSetPropertyException("The document total is zero", PXErrorLevel.Warning));
  }
}


@StevenRatner Thank you it does work correctly but the Error is not very visible i was hoping to still have the popup. The user will see the small warning icon but if they dont see ti or click on it then it will be missed


Hi @dcomerford,

You can override Persist() invoke base(which will commit the record to DB), add condition to verify the total then display the pop-up warning. Following is an example you can try,

        public delegate void PersistDelegate();
[PXOverride]
public void Persist(PersistDelegate baseMethod)
{
baseMethod();
if (Base.Document.Current.CuryLineTotal == 0)
{
// Acuminator disable once PX1050 HardcodedStringInLocalizationMethod [Justification]
throw new PXException("The document total is zero");
}
}

Good Luck,


Reply