0
votes

In Bills and Adjustments, an error message "Please upload invoice" needs to display if user tries to save without attaching/uploading a document.

I created a bool field, UsrFilesAttached, that does not persist. On Rowselected event, i get a count, set bool if 0 or not.

I tried updating AP.APRegister DAC to [PXUIRequired(typeof(Where>))]

I tried something else in the BLC but I can't find it now.

//in APInvoiceEntry
protected void APInvoice_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
    var inv = (APInvoice)e.Row;
    bool attachedFiles = PXNoteAttribute.GetFileNotes(cache, cache.Current).Length != 0;

    cache.SetValueExt<APRegisterExt.usrFilesAttached>(inv, attachedFiles);  
}

// in DAC AP.APRegister
[PXBool]
[PXUIField(DisplayName="UsrFilesAttached")]
[PXDefault]
[PXUIRequired(typeof(Where<usrFilesAttached, Equal<False>>))]

I expect that if UsrFilesAttached is false an error will appear. I am able to save record whether UsrFilesAttached is true or false. Also, how do I add a custom error message?

1

1 Answers

0
votes

This morning, I had a different thought about how to tackle this and it worked. I started over with this and it works:

protected void APInvoice_Hold_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
  var inv = (APInvoice)e.Row;
  if (inv == null)
    return;

  bool attachedFiles = PXNoteAttribute.GetFileNotes(cache, cache.Current).Length != 0;

  if (attachedFiles == false)
    {
      cache.RaiseExceptionHandling<APRegister.hold>(inv, null, new PXSetPropertyException("Please attach invoice", PXErrorLevel.Error));
      inv.Hold = true;
    }   
}

It makes better sense to do the check when trying to release the hold anyway. It can probably be improved on, so please teach me if you know a cleaner way. :)