Skip to main content
Question

How to make a field required


Hello - we are trying to figure out how to make it so that an attachment is required for each expense receipt that is created. How would we make that a required field? 

2 replies

Samvel Petrosov
Jr Varsity II
Forum|alt.badge.img+5

You will have to have/develop a customization checking the file attachments and showing an error message if there are none.

Acumatica allows making “fields” required with no-code/low-code customizations, but in this case there is field tracking the attachments on the records itself that you can make required.

Also, a complication to this validation can be to identify the file that you actually want to track, as technically any attachment (file/pdf/image/etc...) is an attachment. So the program also will need to somehow understand if the correct/required file is attached. 


Nilkanth Dipak
Semi-Pro I
Forum|alt.badge.img+10

Hi ​@ahafemann,

I believe you will need to create a customization to achieve this.

You can write the logic in the RowPersisting event and use a BQL query to fetch the attachment for the current record.

The code snippet below will help you head in the right direction:

using PX.Data;
using PX.Objects.EP; 
using PX.SM;         
using System.Linq;

namespace test
{
    public class ExpenseReceiptEntry_Extension : PXGraphExtension<ExpenseReceiptEntry>
    {
        protected void EPExpenseReceipt_RowPersisting(PXCache cache, PXRowPersistingEventArgs e)
        {
            var row = (EPExpenseReceipt)e.Row;
            if (row == null) return;

            // Check if the document is being inserted or updated
            if (e.Operation != PXDBOperation.Insert && e.Operation != PXDBOperation.Update)
                return;

            // Get the NoteID (attachment link)
            Guid? noteID = row.NoteID;

            if (noteID == null)
            {
                PXTrace.WriteError($"Expense Receipt {row.ReceiptNbr} has no NoteID.");
                return;
            }

            // Check for attachments
            var hasAttachments = PXSelect<UploadFileRevision,
                Where<UploadFileRevision.noteID, Equal<Required<UploadFileRevision.noteID>>>>
                .Select(Base, noteID)
                .Any();

            if (!hasAttachments)
            {
                cache.RaiseExceptionHandling<EPExpenseReceipt.receiptNbr>(
                    row,
                    row.ReceiptNbr,
                    new PXSetPropertyException("An attachment is required for this expense receipt.", PXErrorLevel.Error)
                );

                throw new PXRowPersistingException(
                    nameof(EPExpenseReceipt.receiptNbr),
                    row.ReceiptNbr,
                    "An attachment is required for this expense receipt."
                );
            }
        }
    }
}

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings