Hi all,
I'm having the following scenario: We have a base customization that adds a FieldVerifying handler in ArcContractMaint for ArcContract.CounterpartyID. We have a second customization that must completely replace that validation logic. We need the original handler to NOT run before or after our handler.
The instance version we are using is: Acumatica 2025 R2
Base handler we want to replace:
protected virtual void _(Events.FieldVerifying<ArcContract, ArcContract.counterpartyID> e)
{
ArcContract row = e.Row;
bool flag = row == null || e.NewValue == null;
if (!flag)
{
FeaturesSet current = PXSelectBase<FeaturesSet, PXSelect<FeaturesSet, Where<True, Equal<True>>, OrderBy<Desc<FeaturesSet.status>>>.Config>
.SelectWindowed(this, 0, 1, Array.Empty<object>());
bool? visibilityRestriction = current.VisibilityRestriction;
bool flag2 = false;
bool flag3 = visibilityRestriction.GetValueOrDefault() == flag2 & visibilityRestriction != null;
if (!flag3)
{
bool isBAccountRestricToCurBranch = false;
int? curyBranchID = PXAccess.GetBranchID();
int? orgBAccountID = this.GetOrgBAccountID(curyBranchID);
bool flag4 = row.PurchaseSale == "P";
if (flag4)
{
foreach (PXDataRecord rec in PXDatabase.SelectMulti<BAccount>(new PXDataField[]
{
new PXDataField("VOrgBAccountID"),
new PXDataFieldValue("VOrgBAccountID", orgBAccountID),
new PXDataFieldValue("BAccountID", e.NewValue)
}))
{
isBAccountRestricToCurBranch = true;
}
}
else
{
bool flag5 = row.PurchaseSale == "S";
if (flag5)
{
foreach (PXDataRecord rec2 in PXDatabase.SelectMulti<BAccount>(new PXDataField[]
{
new PXDataField("COrgBAccountID"),
new PXDataFieldValue("COrgBAccountID", orgBAccountID),
new PXDataFieldValue("BAccountID", e.NewValue)
}))
{
isBAccountRestricToCurBranch = true;
}
}
}
bool flag6 = !isBAccountRestricToCurBranch;
if (flag6)
{
e.NewValue = null;
throw new PXSetPropertyException<ArcContract.counterpartyID>(
"Chosen counterparty ID is not associated with current branch. Make some adjustments on AP303000/AR303000 screen.",
new object[] { row });
}
}
}
}My current extension:
using PX.Common;
using PX.Data;
using PX.Objects.CR;
using PX.Objects.CS;
using PX.Objects.GL.DAC;
using System;
using Branch = PX.SM.Branch;
namespace CurrentCustomizationExt
{
[PXLocalizable]
public static class Messages
{
public const string CounterpartyNotAssociatedWithBranch =
"[PCExt] Chosen counterparty is not associated with current branch. Please adjust visibility restrictions on AP303000/AR303000 screen.";
}
public class ArcContractMaintExt : PXGraphExtension<ArcContractMaint>
{
public static bool IsActive() => true;
[PXOverride]
protected virtual void _(Events.FieldVerifying<ArcContract, ArcContract.counterpartyID> e)
{
ArcContract row = e.Row;
if (row == null || e.NewValue == null)
{
return;
}
int? counterpartyID = e.NewValue as int?;
if (counterpartyID == null && e.NewValue is int intVal)
{
counterpartyID = intVal;
}
if (counterpartyID == null)
{
return;
}
FeaturesSet features = PXSelect<FeaturesSet,
Where<True, Equal<True>>,
OrderBy<Desc<FeaturesSet.status>>>
.SelectWindowed(Base, 0, 1);
bool isVisibilityRestrictionEnabled = features?.VisibilityRestriction == true;
if (!isVisibilityRestrictionEnabled)
{
return;
}
int? branchID = row.BranchID ?? Base.Accessinfo.BranchID ?? PXAccess.GetBranchID();
int? orgBAccountID = GetOrgBAccountIDFromBranch(branchID);
bool isValid = ValidateCounterpartyOrganizationMatch(row.PurchaseSale, counterpartyID, orgBAccountID);
if (!isValid)
{
throw new PXSetPropertyException<ArcContract.counterpartyID>(
Messages.CounterpartyNotAssociatedWithBranch);
}
}
// helper methods omitted for brevity
}
}I have tried overriding the handler with delegate but it gives the following error: “Invalid argument type in the event handler ”. At the code current state, its kind of overriding it almost correctly but even when the Counterparty value is valid, its executing the old event handler after mine and throws the exception even when the value is valid