Hello everyone, I have tried to make the attachment field mandatory but was unable to. I need to make it mandatory once the user approve the requisition.
Kindly assist Thank you for continuous support. Any kind of response is always highly appreciated.
Page 1 / 1
You are checking the wrong field from the wrong table. For “Notes” you will need to look into “Note” DAC where Note.NoteID = EPApproval.NoteID and see if “NoteText” has value and for “Files” you will need to look into NoteDoc WHERE NoteDoc.NoteID = EPApproval.NoteID and see if any record exists there.
RowPersisted or any other event handler in your case will not help because the EPApproval record is Auto Generated initially when a document falls into Approval Map. If you put this validation on any event handler of EPApproval DAC your system will stop working. Even if you use RowUpdated, there are some internal records created or auto approval happens that will cause the same problem for you.
You might be able to play with it and incorporate the “Status” field as well as “IsPreApproved” which is used for internal stuff but I think you will face some exception-handlings.
You will need to develop this on your document Graph. What you are trying to make work, won't be so straightforward although seems so. I have played a lot with Approvals and it has a very complicated structure to override as well.
This works on Invoices
protected virtual void _(Events.RowPersisting<ARInvoice> e) { ARInvoice invoice = e.Row; if (invoice is null) return;
var invoiceGraph = (ARInvoiceEntry)e.Cache.Graph;
if (invoice.Status == ARDocStatus.PendingApproval) { PX.Objects.EP.EPApproval approval = invoiceGraph.Approval.Select()?.FirstTableItems?.FirstOrDefault(); if (approval is object) { var files = PXNoteAttribute.GetFileNotes(e.Cache, approval); if (!(files?.Any() ?? false)) Base.Document.Ask("Attachment Required", "The required files are missing from Approvals", MessageButtons.OK, MessageIcon.Error); } } }
I had to use a dialog because throwing an exception will prevent it from saving, and attaching a file requests to save, so it ends up in a loop.
Nice work @darylbowman it definitely gives a great head start. All it needs is a little bit of fine-tuning to check for the Pending Approval records in EPApproval and be triggered only when EPApproval Status changes from Pending to Approved/Rejected. Do not forget to exclude the IsPreApproved from verifications. Cheers pal
All these responses are GREAT!! @aaghaei@darylbowman thanks alot
Looking again, I realize I made that bool non nullable. It should be:
bool? hasFiles = files?.Any()
I don't think you can make a file mandatory in the same way that you can make a field, but you should be able to check the Status value in an Event (perhaps RowPersisting) and throw a PXException if a file is not attached.
I don't think you can make a file mandatory in the same way that you can make a field, but you should be able to check the Status value in an Event (perhaps RowPersisting) and throw a PXException if a file is not attached.
protected void EPApproval_RowPersisted(PXCache cache, PXRowPersistedEventArgs e, PXRowPersisted InvokeBaseHandler) { if(InvokeBaseHandler != null) InvokeBaseHandler(cache, e); var row = (EPApproval)e.Row;
if(row.NoteID == null){
throw new PXException("Kindly attach the AFE");
}
}
Tried to do this but dint work.
I meant RowSelected of the parent record.
You should be able to check for the EPApprovals during the save of the parent record.
I just realized I said RowSelected in my second answer. I meant RowPersisting of the parent record.
This works on Invoices
protected virtual void _(Events.RowPersisting<ARInvoice> e) { ARInvoice invoice = e.Row; if (invoice is null) return;
var invoiceGraph = (ARInvoiceEntry)e.Cache.Graph;
if (invoice.Status == ARDocStatus.PendingApproval) { PX.Objects.EP.EPApproval approval = invoiceGraph.Approval.Select()?.FirstTableItems?.FirstOrDefault(); if (approval is object) { var files = PXNoteAttribute.GetFileNotes(e.Cache, approval); if (!(files?.Any() ?? false)) Base.Document.Ask("Attachment Required", "The required files are missing from Approvals", MessageButtons.OK, MessageIcon.Error); } } }
I had to use a dialog because throwing an exception will prevent it from saving, and attaching a file requests to save, so it ends up in a loop.
I implemented this on Requisition but the system keeps prompting the dialog box even after attaching the file. what could be the reason why?
code:
protected virtual void _(Events.RowPersisting<RQRequisition> e) { RQRequisition requisition = e.Row; RQRequisitionExt reqyyy = PXCache<RQRequisition>.GetExtension<RQRequisitionExt>(requisition); if (requisition is null) return;
var requisitionGraph = (RQRequisitionEntry)e.Cache.Graph;
if (requisition.Status == RQRequisitionStatus.Bidding) { PX.Objects.EP.EPApproval approval = requisitionGraph.Approval.Select()?.FirstTableItems?.FirstOrDefault(); if (approval is object) { var files = PXNoteAttribute.GetFileNotes(e.Cache, approval); if (!(files?.Any() ?? false) )