I am trying to create a customization that requires an attachment on the Bills and Adjustment screen for certain roles.
How should I define the roles that require an attachment and check if that user is in the role?
How do I check for attachments?
Here is the base code I'm using
namespace PX.Objects.AP
{
public class APInvoiceEntry_Extension : PXGraphExtension<APInvoiceEntry>
{
#region Event Handlers
private void _(Events.RowPersisting<APInvoice> e)
{
if (e.Row == null) return;
// Get the current user roles for the AP301000 screen
PXRoleList rolesList = PXAccess.GetRoles("AP301000");
// Extract role IDs using the Roles property
var roles = PXAccess.GetRoles("AP301000");
// Define roles that require an attachment
string[] requiredRoles = { "APClerk", "FinanceManager" };
// Check if the user has any of the required roles
if (requiredRoles.Any(role => roles.Contains(role)))
{
// Check for attachments
bool hasAttachments = SelectFrom<NoteDoc>
.Where<NoteDoc.FileID.IsEqual<@P.AsGuid>>
.View.Select(Base, e.Row.NoteID).Any();
if (!hasAttachments)
{
throw new PXException("Attachment Required","An attachment is required for this bill.", MessageButtons.OK, MessageIcon.Error);
}
}
}
#endregion
}
}