We're looking to add validation to Business Accounts (CR303000) for RowPersisting to double check the user has entered an email address for the Primary Contact.
Although I'm not seeing how to clearly get to the information for the Primary Contact
I see the base graph makes reference to:
Base.GetExtension<PrimaryContactGraphExt>().PrimaryContactCurrent
But the Graph Extension doesn't seem to know about it.
If anyone knows what's the best way to validate the email address being set before the Business accounts get saved, I'd love to hear some insight.
You need to extend PrimartContactGraphExt, and implement your check there.
using PX.Data;
using PX.Objects.CR;
namespace StackOverFlowDemo
{
// Acuminator disable once PX1016 ExtensionDoesNotDeclareIsActiveMethod extension should be constantly active
public class PrimaryContactGraphExtExt : PXGraphExtension<BusinessAccountMaint.PrimaryContactGraphExt, BusinessAccountMaint>
{
protected virtual void _(Events.RowPersisting<Contact> e)
{
if (e.Row?.IsPrimary != true) return;
if (e.Row.EMail == null)
{
// Acuminator disable once PX1050 HardcodedStringInLocalizationMethod [Justification]
e.Cache.RaiseExceptionHandling<Contact.eMail>(e.Row, e.Row.EMail,
new PXSetPropertyException<Contact.eMail>("Email address must not be empty for primary contacts.", PXErrorLevel.RowError));
}
}
}
}