Is it possible to use PXDefault to make a Customers Primary Contact the default selection when creating Service Orders? If so, how?
Answer
Primary Contact as Default on Service Orders
Best answer by DipakNilkanth
Hi
To default the Primary Contact on the Service Orders screen, you’ll need to implement logic within the FieldDefaulting event of the ContactID field. Please find the attached code snippet for reference.
protected virtual void FSServiceOrder_ContactID_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
{
var row = e.Row as FSServiceOrder;
if (row == null || row.CustomerID == null)
return;
// Get Customer's Primary Contact
BAccountR customer = PXSelect<BAccountR,
Where<BAccountR.bAccountID, Equal<Required<BAccountR.bAccountID>>>>
.Select(Base, row.CustomerID);
if (customer?.PrimaryContactID != null)
{
e.NewValue = customer.PrimaryContactID;
e.Cancel = true;
}
}If you want the contact to be updated when a Customer is selected, you can include the logic in the FieldUpdated event of the CustomerID field, as shown below.
protected void FSServiceOrder_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e, PXFieldUpdated InvokeBaseHandler)
{
if(InvokeBaseHandler != null)
InvokeBaseHandler(cache, e);
var row = (FSServiceOrder)e.Row;
if (row == null)
return;
// Clear existing contact to trigger defaulting
cache.SetDefaultExt<FSServiceOrder.contactID>(row);
}Hope, it helps!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.