Basically, I am trying to accomplish something similar to this feature request: Add Credit Hold Warning to Service Order
I need to access the VerifyByCreditRules method that is located in a protected class in the PX.Objects.Extensions.CustomerCreditHold namespace.
The signature for it is:
protected virtual CreditVerificationResult VerifyByCreditRules(PXCache sender, TDoc Row, PX.Objects.AR.Customer customer, CustomerClass customerclass)
I need access it from a ServiceOrderEntry graph.
I read this interesting blog post: Overriding Credit Verification by
I have some source code that compiles, but does not run, since the creditExtensionProtected and creditExtension values are coming back null…
But I am not sure I am even on the right track.
Basically, I want to call VerifyByCreditRules method whenever the ServiceOrder ID is changed to determine if the customer should be placed on credit hold.
How would I do that?
This is where I am right now, but I’m not sure it is even worth considering… It is attached in case I am close, and it might help:
using System;
using System.Collections;
using System.Collections.Generic;
using PX.SM;
using PX.Data;
using PX.Data.BQL;
using PX.Data.BQL.Fluent;
using PX.Objects.FS;
using PX.Objects.CS;
using PX.Objects.IN;
using PX.Objects.AR;
using PX.Objects.Extensions.CustomerCreditHold;
namespace MyCode
{
public class ServiceOrderEntry_Ext : PXGraphExtension<ServiceOrderEntry>
{
public static bool IsActive() => PXAccess.FeatureInstalled<FeaturesSet.serviceManagementModule>();
protected virtual void _(Events.RowSelected<FSServiceOrder> e)
{
var row = (FSServiceOrder)e.Row;
var cache = e.Cache;
if (row == null) return;
string displayStatus = string.Empty;
}
protected virtual void _(Events.RowInserted<FSServiceOrder> e)
{
FSServiceOrder row = e.Row as FSServiceOrder;
var cache = e.Cache;
if (row == null) return;
var currentCustom = row.CustomerID;
}
// Access the CustomerCreditExtension
private CustomerCreditExtension<ServiceOrderProcess, FSServiceOrder, FSServiceOrder.customerID,
FSServiceOrder.hold, FSServiceOrder.completed, FSServiceOrder.status> creditExtension;
private CustomerCreditExtensionProtected creditExtensionProtected;
public override void Initialize()
{
base.Initialize();
creditExtension = Base.GetExtension<CustomerCreditExtension<ServiceOrderProcess, FSServiceOrder, FSServiceOrder.customerID,
FSServiceOrder.hold, FSServiceOrder.completed, FSServiceOrder.status>>();
creditExtensionProtected = Base.GetExtension<CustomerCreditExtensionProtected>();
}
// Method to check customer credit status
public CreditVerificationResult CheckCustomerCreditStatus(FSServiceOrder serviceOrder)
{
PXCache cache = Base.CachesCtypeof(FSServiceOrder)];
PX.Objects.AR.Customer customer = GetCustomer(cache, serviceOrder);
if (customer == null) return null;
CustomerClass customerClass = GetCustomerClass(cache, customer);
if (customer != null && customerClass != null)
{
return creditExtensionProtected.VerifyByCreditRules(cache, serviceOrder, customer, customerClass);
}
return null;
}
private PX.Objects.AR.Customer GetCustomer(PXCache cache, FSServiceOrder serviceOrder)
{
return SelectFrom<PX.Objects.AR.Customer>
.Where<PX.Objects.AR.Customer.bAccountID.IsEqual<@P.AsInt>>
.View.Select(Base, serviceOrder.CustomerID).TopFirst;
}
private CustomerClass GetCustomerClass(PXCache cache, PX.Objects.AR.Customer customer)
{
return SelectFrom<CustomerClass>
.Where<CustomerClass.customerClassID.IsEqual<@P.AsString>>
.View.Select(Base, customer.CustomerClassID).TopFirst;
}
private void ApplyCreditVerificationResult(CreditVerificationResult result)
{
if (result != null && result.Failed)
{
// Handle the credit verification failure (e.g., place the order on hold, show a warning, etc.)
// throw new PXException(result.ErrorMessage);
}
}
protected virtual void _(Events.FieldUpdated<FSServiceOrder, FSServiceOrder.customerID> e)
{
{
FSServiceOrder serviceOrder = (FSServiceOrder)e.Row;
CreditVerificationResult result = CheckCustomerCreditStatus(serviceOrder);
if (result != null && result.Failed)
{
// Handle the credit verification failure
ApplyCreditVerificationResult(result);
}
}
}
// Class to access the protected CreditExtension
iPXProtectedAccess(typeof(CustomerCreditExtension<ServiceOrderProcess, FSServiceOrder, FSServiceOrder.customerID, FSServiceOrder.hold, FSServiceOrder.completed, FSServiceOrder.status>))]
public abstract class CustomerCreditExtensionProtected : PXGraphExtension<CustomerCreditExtension<ServiceOrderProcess, FSServiceOrder, FSServiceOrder.customerID, FSServiceOrder.hold, FSServiceOrder.completed, FSServiceOrder.status>, ServiceOrderProcess>
{
PXProtectedAccess]
internal abstract CreditVerificationResult VerifyByCreditRules(PXCache cache, FSServiceOrder serviceOrder, Customer customer, CustomerClass customerClass);
}
}
}