Skip to main content
Answer

Primary Contact as Default on Service Orders

  • May 13, 2025
  • 3 replies
  • 80 views

Forum|alt.badge.img

Is it possible to use PXDefault to make a Customers Primary Contact the default selection when creating Service Orders? If so, how?

Best answer by DipakNilkanth

Hi ​@bobbytherbs,

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!

3 replies

DipakNilkanth
Pro III
Forum|alt.badge.img+13

Hi ​@bobbytherbs,

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!


Forum|alt.badge.img
  • Author
  • Freshman I
  • May 14, 2025

@Nilkanth Dipak thank you! This worked perfectly!


Bravo94
Freshman I
Forum|alt.badge.img
  • Freshman I
  • September 22, 2025

Hi guys,

do u know how i can display the Primary Contact (from vendor) in purchase order ?