Hi team,
I want a customization where, when a user creates a claim, the attachment in the Details tab becomes mandatory. I tried many events like persist, persisted, rowSelected, but I’m getting an error. I’m unable to attach an attachment because the error still appears. Is there any solution?
using PX.Data;
using PX.Objects.EP;
using System.Linq;
namespace PX.Objects.EP
{
public class ExpenseClaimEntry_Extension : PXGraphExtension<ExpenseClaimEntry>
{
#region Event Handlers
/// <summary>
/// Validates that expense claim detail has an attachment when InventoryID is blank
/// </summary>
protected virtual void _(Events.RowPersisting<EPExpenseClaimDetails> e)
{
EPExpenseClaimDetails detail = e.Row;
if (detail is null) return;
var claimGraph = (ExpenseClaimEntry)e.Cache.Graph;
// Check if InventoryID is blank/null
if (detail.InventoryID == null)
{
// Get files attached to the detail line
var files = PXNoteAttribute.GetFileNotes(e.Cache, detail);
// Use nullable bool to properly handle the null case
bool? hasFiles = files?.Any();
// If no files attached, show error dialog
if (!(hasFiles ?? false))
{
Base.ExpenseClaimDetails.Ask(
"Attachment Required",
"File attachment is required when Inventory ID is blank.",
MessageButtons.OK,
MessageIcon.Error
);
}
}
}
#endregion
}
}
I referred to this blog, and I am also facing the same issue. The error message keeps getting triggered again and again, even if I want to add an attachment.
