Skip to main content
Answer

Primary Contact as Default on Appointments

  • May 15, 2025
  • 2 replies
  • 85 views

Forum|alt.badge.img

Would like to create a Customization to populate a Customers Primary Contact in the contact field of the settings tab on an appointment by default. Please help!

Best answer by Abhishek Niikam

Hi ​@bobbytherbs, to populate a Customers Primary Contact in the contact field of the settings tab on an appointment by default. Please find the attached code snippet which I used recently.
 

protected void FSAppointment_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
FSAppointment appointment = e.Row as FSAppointment;
if (appointment == null || appointment.CustomerID == null)
return;

// Retrieve the Customer's Primary Contact
BAccount baccount = PXSelect<BAccount,
Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>
.Select(Base, appointment.CustomerID);

if (baccount?.PrimaryContactID != null)
{
// Get the related Service Order record
FSServiceOrder serviceOrder = PXSelect<FSServiceOrder,
Where<FSServiceOrder.srvOrdType, Equal<Required<FSServiceOrder.srvOrdType>>,
And<FSServiceOrder.refNbr, Equal<Required<FSServiceOrder.refNbr>>>>>
.Select(Base, appointment.SrvOrdType, appointment.RefNbr);

if (serviceOrder != null)
{
serviceOrder.ContactID = baccount.PrimaryContactID;
Base.ServiceOrderRelated.Update(serviceOrder);
}
}
}

Hope, it helps!

2 replies

Forum|alt.badge.img+2

Hi ​@bobbytherbs, to populate a Customers Primary Contact in the contact field of the settings tab on an appointment by default. Please find the attached code snippet which I used recently.
 

protected void FSAppointment_CustomerID_FieldUpdated(PXCache cache, PXFieldUpdatedEventArgs e)
{
FSAppointment appointment = e.Row as FSAppointment;
if (appointment == null || appointment.CustomerID == null)
return;

// Retrieve the Customer's Primary Contact
BAccount baccount = PXSelect<BAccount,
Where<BAccount.bAccountID, Equal<Required<BAccount.bAccountID>>>>
.Select(Base, appointment.CustomerID);

if (baccount?.PrimaryContactID != null)
{
// Get the related Service Order record
FSServiceOrder serviceOrder = PXSelect<FSServiceOrder,
Where<FSServiceOrder.srvOrdType, Equal<Required<FSServiceOrder.srvOrdType>>,
And<FSServiceOrder.refNbr, Equal<Required<FSServiceOrder.refNbr>>>>>
.Select(Base, appointment.SrvOrdType, appointment.RefNbr);

if (serviceOrder != null)
{
serviceOrder.ContactID = baccount.PrimaryContactID;
Base.ServiceOrderRelated.Update(serviceOrder);
}
}
}

Hope, it helps!


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

@Abhishek Niikam this worked great! Thank you!